Upload 7 files
Browse filesFiles changed (7)
- README.mdAdded+118
- config (1).jsonAdded+36
- merges.txtAdded
- model (1).safetensorsAdded+3
- special_tokens_map (1).jsonAdded+51
- tokenizer_config (1).jsonAdded+65
- vocab.jsonAdded
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118# RoBERTa-Base Model for Temporal Information Extraction
This repository hosts a fine-tuned version of RoBERTa for **temporal information extraction**, where the model identifies and extracts time-related expressions (e.g., dates, durations) from text. The pipeline includes preprocessing, fine-tuning, and inference on labeled temporal datasets.
---
## Model Details
- **Model Name:** RoBERTa-Base
- **Model Architecture:** RoBERTa Token Classification
- **Task:** Temporal Entity Extraction
- **Dataset:** Custom JSON format with annotated temporal SPO triples
- **Fine-tuning Framework:** Hugging Face Transformers
- **Output Labels:** `B-TIMEX`, `I-TIMEX`, `O`
---
## Usage
### Installation
```bash
pip install transformers datasets evaluate
# Loading the Fine-Tuned Model
from transformers import RobertaTokenizerFast, RobertaForTokenClassification
import torch
# Load model and tokenizer
model = RobertaForTokenClassification.from_pretrained("./temporal_model")
tokenizer = RobertaTokenizerFast.from_pretrained("./temporal_model", add_prefix_space=True)
# Inference function
def extract_temporal_entities(text):
tokens = text.split()
inputs = tokenizer(tokens, return_tensors="pt", is_split_into_words=True)
outputs = model(**inputs)
predictions = outputs.logits.argmax(dim=-1).squeeze().tolist()
word_ids = inputs.word_ids()[0]
temporal_spans = []
current = []
for idx, word_idx in enumerate(word_ids):
if word_idx is None:
continue
label = id2label[predictions[idx]]
if label == "B-TIMEX":
if current:
temporal_spans.append(" ".join(current))
current = [tokens[word_idx]]
elif label == "I-TIMEX":
current.append(tokens[word_idx])
else:
if current:
temporal_spans.append(" ".join(current))
current = []
if current:
temporal_spans.append(" ".join(current))
return temporal_spans
# Performance Metrics
Evaluation Accuracy: ~0.76
F1 Score: Tracked using seqeval (BIO format)
Evaluation Strategy: epoch
# Fine-Tuning Details
Dataset
The dataset consists of manually or script-labeled SPO-style JSON entries with the following fields:
text: Raw input string
spo_list: A list of subject-predicate-object relations, including:
Subject & Object Span
Type (e.g., Date, Location)
The text is tokenized, and BIO labels are applied for token classification.
# Training Configuration
Epochs: 3
Batch Size: 16
Learning Rate: 2e-5
Max Sequence Length: 128 tokens
Tokenizer: roberta-base with add_prefix_space=True
# Repository Structure
pgsql
Copy
Edit
.
βββ temporal_model/ # Fine-tuned model and tokenizer
β βββ config.json
β βββ pytorch_model.bin
β βββ tokenizer_config.json
β βββ vocab.json
β βββ special_tokens_map.json
βββ temporal-information-extraction.ipynb
βββ README.md
# Limitations
The model is domain-specific; generalization to other types of temporal expressions (e.g., informal text) may require additional training.
BIO tagging may fail in overlapping or nested entity scenarios.
# Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request to improve model performance or add new datasets.
123456789101112131415161718192021222324252627282930313233343536{ "architectures": [ "RobertaForTokenClassification" ], "attention_probs_dropout_prob": 0.1, "bos_token_id": 0, "classifier_dropout": null, "eos_token_id": 2, "hidden_act": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 768, "id2label": { "0": "LABEL_0", "1": "LABEL_1", "2": "LABEL_2" }, "initializer_range": 0.02, "intermediate_size": 3072, "label2id": { "LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2 }, "layer_norm_eps": 1e-05, "max_position_embeddings": 514, "model_type": "roberta", "num_attention_heads": 12, "num_hidden_layers": 12, "pad_token_id": 1, "position_embedding_type": "absolute", "torch_dtype": "float16", "transformers_version": "4.51.3", "type_vocab_size": 1, "use_cache": true, "vocab_size": 50265}123version https://git-lfs.github.com/spec/v1oid sha256:0007fb807b07d163f3b7b1782b6c3aae9829d594abd477327ddfab522052db82size 248138558123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051{ "bos_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "cls_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "eos_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "mask_token": { "content": "<mask>", "lstrip": true, "normalized": false, "rstrip": false, "single_word": false }, "pad_token": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "sep_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "unk_token": { "content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465{ "add_prefix_space": true, "added_tokens_decoder": { "0": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "1": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "2": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "3": { "content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50264": { "content": "<mask>", "lstrip": true, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "<s>", "clean_up_tokenization_spaces": false, "cls_token": "<s>", "eos_token": "</s>", "errors": "replace", "extra_special_tokens": {}, "mask_token": "<mask>", "max_length": 128, "model_max_length": 512, "pad_to_multiple_of": null, "pad_token": "<pad>", "pad_token_type_id": 0, "padding_side": "right", "sep_token": "</s>", "stride": 0, "tokenizer_class": "RobertaTokenizer", "trim_offsets": true, "truncation_side": "right", "truncation_strategy": "longest_first", "unk_token": "<unk>"}README.mdAdded+118
config (1).jsonAdded+36
merges.txtAdded
model (1).safetensorsAdded+3
special_tokens_map (1).jsonAdded+51
tokenizer_config (1).jsonAdded+65
vocab.jsonAdded