Views
No views yet
| armenian | bosnian | bulgarian | catalan | croatian |
| czech | danish | dutch | english | estonian |
| finnish | french | galician | georgian | german |
| greek | hebrew | hungarian | icelandic | italian |
| japanese | korean | latvian | lithuanian | macedonian |
| montenegrin | norwegian | polish | portuguese | romanian |
| russian | serbian | slovak | slovenian | spanish |
| swedish | turkish | ukrainian |
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model = AutoModelForSequenceClassification.from_pretrained("manifesto-project/manifestoberta-xlm-roberta-56policy-topics-sentence-2023-1-1")
5tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-large")
6
7sentence = "We will restore funding to the Global Environment Facility and the Intergovernmental Panel on Climate Change, to support critical climate science research around the world"
8
9inputs = tokenizer(sentence,
10 return_tensors="pt",
11 max_length=200, #we limited the input to 200 tokens during finetuning
12 padding="max_length",
13 truncation=True
14 )
15
16logits = model(**inputs).logits
17
18probabilities = torch.softmax(logits, dim=1).tolist()[0]
19probabilities = {model.config.id2label[index]: round(probability * 100, 2) for index, probability in enumerate(probabilities)}
20probabilities = dict(sorted(probabilities.items(), key=lambda item: item[1], reverse=True))
21print(probabilities)
22# {'501 - Environmental Protection: Positive': 67.28, '411 - Technology and Infrastructure': 15.19, '107 - Internationalism: Positive': 13.63, '416 - Anti-Growth Economy: Positive': 2.02...
23
24predicted_class = model.config.id2label[logits.argmax().item()]
25print(predicted_class)
26# 501 - Environmental Protection: Positive| Accuracy | Top2_Acc | Top3_Acc | Precision | Recall | F1_Macro | MCC | Cross-Entropy | |
|---|---|---|---|---|---|---|---|---|
| Sentence Model | 0.57 | 0.73 | 0.81 | 0.49 | 0.43 | 0.45 | 0.55 | 1.5 |
| Context Model | 0.64 | 0.81 | 0.88 | 0.54 | 0.52 | 0.53 | 0.62 | 1.15 |
1@misc{Burst:2023,
2 Address = {Berlin / Göttingen},
3 Author = {Burst, Tobias AND Lehmann, Pola AND Franzmann, Simon AND Al-Gaddooa, Denise AND Ivanusch, Christoph AND Regel, Sven AND Riethmüller, Felicia AND Weßels, Bernhard AND Zehnter, Lisa},
4 Publisher = {Wissenschaftszentrum Berlin für Sozialforschung / Göttinger Institut für Demokratieforschung},
5 Title = {manifestoberta. Version 56topics.sentence.2023.1.1},
6 doi = {10.25522/manifesto.manifestoberta.56topics.sentence.2023.1.1},
7 url = {https://doi.org/10.25522/manifesto.manifestoberta.56topics.sentence.2023.1.1},
8 Year = {2023},