Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
tags: []
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# Model Card for Model ID
|
| 7 |
+
|
| 8 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
## Model Details
|
| 13 |
+
|
| 14 |
+
### Model Description
|
| 15 |
+
|
| 16 |
+
### How to use the model
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
import pandas as pd
|
| 20 |
+
import numpy as np
|
| 21 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 22 |
+
|
| 23 |
+
# Load model
|
| 24 |
+
model = AutoModelForSequenceClassification.from_pretrained("lkonle/EMO_Sadness_gbert")
|
| 25 |
+
|
| 26 |
+
# Load tokenizer
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained("lkonle/EMO_Sadness_gbert")
|
| 28 |
+
tokenizer.pad_token = "[PAD]"
|
| 29 |
+
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
| 30 |
+
|
| 31 |
+
# define input text
|
| 32 |
+
myinput = ["Paul war sehr sehr glücklich über seinen Welpen.",
|
| 33 |
+
"Paul war sehr traurig über sein Frühstück.",
|
| 34 |
+
"Paul hatte große Langeweile."]
|
| 35 |
+
|
| 36 |
+
# tokenize, encode, format as batch and return pytorch tensors
|
| 37 |
+
input_ids = tokenizer.batch_encode_plus(myinput, truncation=True, padding="max_length", padding_side="right", return_tensors="pt")
|
| 38 |
+
|
| 39 |
+
# predict
|
| 40 |
+
logits = model(**input_ids)["logits"]
|
| 41 |
+
|
| 42 |
+
# get the predicted label
|
| 43 |
+
result = logits.detach().numpy()
|
| 44 |
+
prediction = np.argmax(result, axis=1)
|
| 45 |
+
|
| 46 |
+
# store result in pandas
|
| 47 |
+
output = pd.DataFrame()
|
| 48 |
+
output["inputs"] = myinput
|
| 49 |
+
output["prediction"] = prediction
|
| 50 |
+
print(output)
|
| 51 |
+
```
|