Upload 7 files
Browse files- README.md +118 -0
- config (1).json +36 -0
- merges.txt +0 -0
- model (1).safetensors +3 -0
- special_tokens_map (1).json +51 -0
- tokenizer_config (1).json +65 -0
- vocab.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# RoBERTa-Base Model for Temporal Information Extraction
|
| 2 |
+
|
| 3 |
+
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.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Model Details
|
| 8 |
+
|
| 9 |
+
- **Model Name:** RoBERTa-Base
|
| 10 |
+
- **Model Architecture:** RoBERTa Token Classification
|
| 11 |
+
- **Task:** Temporal Entity Extraction
|
| 12 |
+
- **Dataset:** Custom JSON format with annotated temporal SPO triples
|
| 13 |
+
- **Fine-tuning Framework:** Hugging Face Transformers
|
| 14 |
+
- **Output Labels:** `B-TIMEX`, `I-TIMEX`, `O`
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## Usage
|
| 19 |
+
|
| 20 |
+
### Installation
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
pip install transformers datasets evaluate
|
| 24 |
+
|
| 25 |
+
# Loading the Fine-Tuned Model
|
| 26 |
+
|
| 27 |
+
from transformers import RobertaTokenizerFast, RobertaForTokenClassification
|
| 28 |
+
import torch
|
| 29 |
+
|
| 30 |
+
# Load model and tokenizer
|
| 31 |
+
model = RobertaForTokenClassification.from_pretrained("./temporal_model")
|
| 32 |
+
tokenizer = RobertaTokenizerFast.from_pretrained("./temporal_model", add_prefix_space=True)
|
| 33 |
+
|
| 34 |
+
# Inference function
|
| 35 |
+
def extract_temporal_entities(text):
|
| 36 |
+
tokens = text.split()
|
| 37 |
+
inputs = tokenizer(tokens, return_tensors="pt", is_split_into_words=True)
|
| 38 |
+
outputs = model(**inputs)
|
| 39 |
+
predictions = outputs.logits.argmax(dim=-1).squeeze().tolist()
|
| 40 |
+
word_ids = inputs.word_ids()[0]
|
| 41 |
+
|
| 42 |
+
temporal_spans = []
|
| 43 |
+
current = []
|
| 44 |
+
for idx, word_idx in enumerate(word_ids):
|
| 45 |
+
if word_idx is None:
|
| 46 |
+
continue
|
| 47 |
+
label = id2label[predictions[idx]]
|
| 48 |
+
if label == "B-TIMEX":
|
| 49 |
+
if current:
|
| 50 |
+
temporal_spans.append(" ".join(current))
|
| 51 |
+
current = [tokens[word_idx]]
|
| 52 |
+
elif label == "I-TIMEX":
|
| 53 |
+
current.append(tokens[word_idx])
|
| 54 |
+
else:
|
| 55 |
+
if current:
|
| 56 |
+
temporal_spans.append(" ".join(current))
|
| 57 |
+
current = []
|
| 58 |
+
if current:
|
| 59 |
+
temporal_spans.append(" ".join(current))
|
| 60 |
+
return temporal_spans
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# Performance Metrics
|
| 64 |
+
Evaluation Accuracy: ~0.76
|
| 65 |
+
|
| 66 |
+
F1 Score: Tracked using seqeval (BIO format)
|
| 67 |
+
|
| 68 |
+
Evaluation Strategy: epoch
|
| 69 |
+
|
| 70 |
+
# Fine-Tuning Details
|
| 71 |
+
Dataset
|
| 72 |
+
The dataset consists of manually or script-labeled SPO-style JSON entries with the following fields:
|
| 73 |
+
|
| 74 |
+
text: Raw input string
|
| 75 |
+
|
| 76 |
+
spo_list: A list of subject-predicate-object relations, including:
|
| 77 |
+
|
| 78 |
+
Subject & Object Span
|
| 79 |
+
|
| 80 |
+
Type (e.g., Date, Location)
|
| 81 |
+
|
| 82 |
+
The text is tokenized, and BIO labels are applied for token classification.
|
| 83 |
+
|
| 84 |
+
# Training Configuration
|
| 85 |
+
|
| 86 |
+
Epochs: 3
|
| 87 |
+
|
| 88 |
+
Batch Size: 16
|
| 89 |
+
|
| 90 |
+
Learning Rate: 2e-5
|
| 91 |
+
|
| 92 |
+
Max Sequence Length: 128 tokens
|
| 93 |
+
|
| 94 |
+
Tokenizer: roberta-base with add_prefix_space=True
|
| 95 |
+
|
| 96 |
+
# Repository Structure
|
| 97 |
+
pgsql
|
| 98 |
+
Copy
|
| 99 |
+
Edit
|
| 100 |
+
.
|
| 101 |
+
├── temporal_model/ # Fine-tuned model and tokenizer
|
| 102 |
+
│ ├── config.json
|
| 103 |
+
│ ├── pytorch_model.bin
|
| 104 |
+
│ ├── tokenizer_config.json
|
| 105 |
+
│ ├── vocab.json
|
| 106 |
+
│ └── special_tokens_map.json
|
| 107 |
+
├── temporal-information-extraction.ipynb
|
| 108 |
+
├── README.md
|
| 109 |
+
|
| 110 |
+
# Limitations
|
| 111 |
+
|
| 112 |
+
The model is domain-specific; generalization to other types of temporal expressions (e.g., informal text) may require additional training.
|
| 113 |
+
|
| 114 |
+
BIO tagging may fail in overlapping or nested entity scenarios.
|
| 115 |
+
|
| 116 |
+
# Contributing
|
| 117 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request to improve model performance or add new datasets.
|
| 118 |
+
|
config (1).json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"RobertaForTokenClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"bos_token_id": 0,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "LABEL_0",
|
| 14 |
+
"1": "LABEL_1",
|
| 15 |
+
"2": "LABEL_2"
|
| 16 |
+
},
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 3072,
|
| 19 |
+
"label2id": {
|
| 20 |
+
"LABEL_0": 0,
|
| 21 |
+
"LABEL_1": 1,
|
| 22 |
+
"LABEL_2": 2
|
| 23 |
+
},
|
| 24 |
+
"layer_norm_eps": 1e-05,
|
| 25 |
+
"max_position_embeddings": 514,
|
| 26 |
+
"model_type": "roberta",
|
| 27 |
+
"num_attention_heads": 12,
|
| 28 |
+
"num_hidden_layers": 12,
|
| 29 |
+
"pad_token_id": 1,
|
| 30 |
+
"position_embedding_type": "absolute",
|
| 31 |
+
"torch_dtype": "float16",
|
| 32 |
+
"transformers_version": "4.51.3",
|
| 33 |
+
"type_vocab_size": 1,
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 50265
|
| 36 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model (1).safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0007fb807b07d163f3b7b1782b6c3aae9829d594abd477327ddfab522052db82
|
| 3 |
+
size 248138558
|
special_tokens_map (1).json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"cls_token": {
|
| 10 |
+
"content": "<s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"eos_token": {
|
| 17 |
+
"content": "</s>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": true,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"mask_token": {
|
| 24 |
+
"content": "<mask>",
|
| 25 |
+
"lstrip": true,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"pad_token": {
|
| 31 |
+
"content": "<pad>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": true,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
},
|
| 37 |
+
"sep_token": {
|
| 38 |
+
"content": "</s>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": true,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false
|
| 43 |
+
},
|
| 44 |
+
"unk_token": {
|
| 45 |
+
"content": "<unk>",
|
| 46 |
+
"lstrip": false,
|
| 47 |
+
"normalized": true,
|
| 48 |
+
"rstrip": false,
|
| 49 |
+
"single_word": false
|
| 50 |
+
}
|
| 51 |
+
}
|
tokenizer_config (1).json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"0": {
|
| 5 |
+
"content": "<s>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"1": {
|
| 13 |
+
"content": "<pad>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": true,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"2": {
|
| 21 |
+
"content": "</s>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": true,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"3": {
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": true,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"50264": {
|
| 37 |
+
"content": "<mask>",
|
| 38 |
+
"lstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"bos_token": "<s>",
|
| 46 |
+
"clean_up_tokenization_spaces": false,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"extra_special_tokens": {},
|
| 51 |
+
"mask_token": "<mask>",
|
| 52 |
+
"max_length": 128,
|
| 53 |
+
"model_max_length": 512,
|
| 54 |
+
"pad_to_multiple_of": null,
|
| 55 |
+
"pad_token": "<pad>",
|
| 56 |
+
"pad_token_type_id": 0,
|
| 57 |
+
"padding_side": "right",
|
| 58 |
+
"sep_token": "</s>",
|
| 59 |
+
"stride": 0,
|
| 60 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 61 |
+
"trim_offsets": true,
|
| 62 |
+
"truncation_side": "right",
|
| 63 |
+
"truncation_strategy": "longest_first",
|
| 64 |
+
"unk_token": "<unk>"
|
| 65 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|