pere commited on
Commit
c9065f4
1 Parent(s): 514f0d4
Files changed (1) hide show
  1. evaluate.py +38 -0
evaluate.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForMaskedLM
2
+ from transformers import RobertaTokenizer, RobertaTokenizerFast, RobertaForMaskedLM, pipeline
3
+ import torch
4
+
5
+ def evaluate(framework):
6
+ text = "På biblioteket kan du [MASK] en bok."
7
+ if framework == "flax":
8
+ model = AutoModelForMaskedLM.from_pretrained("./", from_flax=True)
9
+ elif framework == "tensorflow":
10
+ model = AutoModelForMaskedLM.from_pretrained("./", from_tf=True)
11
+ else:
12
+ model = AutoModelForMaskedLM.from_pretrained("./")
13
+
14
+ print("Testing with AutoTokenizer")
15
+ tokenizer = AutoTokenizer.from_pretrained("./")
16
+ my_unmasker_pipeline = pipeline('fill-mask', model=model, tokenizer=tokenizer)
17
+ output = my_unmasker_pipeline(text)
18
+ print(output)
19
+
20
+ #print("\n\nTesting with RobertaTokenizer")
21
+ #tokenizer = RobertaTokenizer.from_pretrained("./")
22
+ #my_unmasker_pipeline = pipeline('fill-mask', model=model, tokenizer=tokenizer)
23
+ #output = my_unmasker_pipeline(text)
24
+ #print(output)
25
+
26
+ #print("\n\nTesting with RobertaTokenizerFast")
27
+ #tokenizer = RobertaTokenizerFast.from_pretrained("./")
28
+ #my_unmasker_pipeline = pipeline('fill-mask', model=model, tokenizer=tokenizer)
29
+ #output = my_unmasker_pipeline(text)
30
+ #print(output)
31
+
32
+
33
+ print("Evaluating PyTorch Model")
34
+ evaluate("pytorch")
35
+
36
+
37
+ #print("Evaluating Flax Model")
38
+ #evaluate("flax")