system HF staff commited on
Commit
36923d7
1 Parent(s): ddf9820

Update SA-TR.py

Browse files
Files changed (1) hide show
  1. SA-TR.py +27 -0
SA-TR.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
3
+
4
+ model= transformers.AutoModelForSequenceClassification.from_pretrained(".")
5
+ tokenizer=transformers.AutoTokenizer.from_pretrained(".")
6
+
7
+
8
+
9
+
10
+ dosya=["dvd.tsv","Books.tsv","Kitchen.tsv","electronics.tsv"][3]
11
+
12
+
13
+
14
+ data = [line.strip().split("\t") for line in open(dosya)]
15
+
16
+ sa= pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
17
+
18
+
19
+ real=[d[1] for d in data]
20
+
21
+ pred=[sa(d[0]) for d in data]
22
+ pred2=[p[0]['label'].split("_")[1] for p in pred]
23
+
24
+
25
+ res=[a==b for (a,b) in zip(pred2, real)]
26
+ sum(res)/len(res)
27
+