Downloads · 30 days
20
18% of all-time downloads
causal-narrative/roberta-causal-span-extractor
roberta-causal-span-extractor is a token classification model from causal-narrative. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as mit.
This model is a fine-tuned version of roberta-base for causal span extraction (token classification). It identifies cause and effect text spans in sentences.
Downloads · 30 days
20
18% of all-time downloads
All-time downloads
112
Public
Parameters
124M
496 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors496 MB · 99%
From the Hugging Face model README
This model is a fine-tuned version of roberta-base for causal span extraction
(token classification). It identifies cause and effect text spans in sentences.
See the training notebook for detailed metrics.
from transformers import RobertaTokenizerFast, RobertaForTokenClassification
import torch
model_name = "causal-narrative/roberta-causal-span-extractor"
tokenizer = RobertaTokenizerFast.from_pretrained(model_name, add_prefix_space=True)
model = RobertaForTokenClassification.from_pretrained(model_name)
text = "The heavy rain caused flooding in the city."
words = text.split()
inputs = tokenizer(words, is_split_into_words=True, return_tensors="pt",
truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
preds = torch.argmax(outputs.logits, dim=2)[0]
id2label = model.config.id2label
word_ids = tokenizer(words, is_split_into_words=True).word_ids()
prev = None
for wid in word_ids:
if wid is not None and wid != prev:
print(f"{words[wid]:20s} {id2label[preds[word_ids.index(wid)].item()]}")
prev = wid
| Label | Description |
|---|---|
| O | Non-causal token |
| B-CAUSE | Beginning of cause span |
| I-CAUSE | Inside cause span |
| B-EFFECT | Beginning of effect span |
| I-EFFECT | Inside effect span |