Emma0123 commited on
Commit
bd0a6b5
1 Parent(s): 528132c

Create ESGmodel

Browse files
Files changed (1) hide show
  1. ESGmodel +32 -0
ESGmodel ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+
4
+
5
+ import torch
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
7
+
8
+ # 加载第一个模型
9
+ tokenizer1 = AutoTokenizer.from_pretrained("Emma0123/fine_tuned_model")
10
+ model1 = AutoModelForSequenceClassification.from_pretrained("Emma0123/fine_tuned_model")
11
+
12
+ # 加载第二个模型
13
+ tokenizer2 = AutoTokenizer.from_pretrained("jonas/roberta-base-finetuned-sdg")
14
+ model2 = AutoModelForSequenceClassification.from_pretrained("jonas/roberta-base-finetuned-sdg")
15
+
16
+ # 输入文本
17
+ input_text = input()
18
+
19
+ # 对第一个模型进行推理
20
+ inputs = tokenizer1(input_text, return_tensors="pt", truncation=True)
21
+ outputs = model1(**inputs)
22
+ predictions = torch.argmax(outputs.logits, dim=1).item()
23
+
24
+ # 根据第一个模型的输出进行条件判断
25
+ if predictions == 1:
26
+ # 使用第二个模型进行判断
27
+ inputs2 = tokenizer2(input_text, return_tensors="pt", truncation=True)
28
+ outputs2 = model2(**inputs2)
29
+ predictions2 = torch.argmax(outputs2.logits, dim=1).item()
30
+ print("Second model prediction:", predictions2)
31
+ else:
32
+ print("This content is unrelated to Environment.")