Views
No views yet
| Metric | Score |
|---|---|
| Accuracy | 0.71 |
| Macro F1 | 0.72 |
| Weighted F1 | n/a |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "docre-mistral-7b-v0.3"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Example usage
10text = "Your document text here."
11head_entity = "Entity 1"
12tail_entity = "Entity 2"
13
14# Format input
15input_text = f"{text} [SEP] {head_entity} [SEP] {tail_entity}"
16
17# Tokenize and predict
18inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)
19with torch.no_grad():
20 outputs = model(**inputs)
21 predicted_class = torch.argmax(outputs.logits, dim=-1)
22
23# Get relation label
24relation = model.config.id2label[predicted_class.item()]
25print(f"Predicted relation: {relation}")1@inproceedings{tan-etal-2022-revisiting,
2 title = "Revisiting DocRED -- Addressing the False Negative Problem in Relation Extraction",
3 author = "Tan, Qingyu and He, Ruidan and Bing, Lidong and Ng, Hwee Tou",
4 booktitle = "Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing",
5 year = "2022"
6}