lkonle commited on
Commit
817a63b
·
verified ·
1 Parent(s): 33720b9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -1
README.md CHANGED
@@ -13,4 +13,39 @@ tags: []
13
 
14
  ### Model Description
15
 
16
- ### How to use the model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Joy_gbert")
25
+
26
+ # Load tokenizer
27
+ tokenizer = AutoTokenizer.from_pretrained("lkonle/EMO_Joy_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
+ ```