scfengv commited on
Commit
18f29f1
·
1 Parent(s): 0b3a0a7

Upload inference example

Browse files
inference_example_1.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ model = AutoModelForSequenceClassification.from_pretrained(
5
+ "scfengv/TVL_GeneralLayerClassifier",
6
+ id2label = {0: "Cheer", 1: "Game", 2: "Broadcast", 3: "Chat"},
7
+ label2id = {"Cheer": 0, "Game": 1, "Broadcast": 2, "Chat": 3}
8
+ )
9
+ tokenizer = AutoTokenizer.from_pretrained("scfengv/TVL_GeneralLayerClassifier")
10
+
11
+ inputs = tokenizer("中纖加油加油加油加油加油", return_tensors = "pt")
12
+
13
+ with torch.no_grad():
14
+ logits = model(**inputs).logits
15
+
16
+ predicted_class_id = logits.argmax().item()
17
+ print(f"Predicted class: {predicted_class_id}")
inference_example_2.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ model = AutoModelForSequenceClassification.from_pretrained(
5
+ "scfengv/TVL_GeneralLayerClassifier",
6
+ id2label = {0: "Cheer", 1: "Game", 2: "Broadcast", 3: "Chat"},
7
+ label2id = {"Cheer": 0, "Game": 1, "Broadcast": 2, "Chat": 3}
8
+ )
9
+ tokenizer = AutoTokenizer.from_pretrained("scfengv/TVL_GeneralLayerClassifier")
10
+
11
+ inputs = tokenizer("導播幽默~", return_tensors = "pt")
12
+
13
+ with torch.no_grad():
14
+ logits = model(**inputs).logits
15
+
16
+ predicted_class_id = logits.argmax().item()
17
+ print(f"Predicted class: {predicted_class_id}")
inference_example_3.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ model = AutoModelForSequenceClassification.from_pretrained(
5
+ "scfengv/TVL_GeneralLayerClassifier",
6
+ id2label = {0: "Cheer", 1: "Game", 2: "Broadcast", 3: "Chat"},
7
+ label2id = {"Cheer": 0, "Game": 1, "Broadcast": 2, "Chat": 3}
8
+ )
9
+ tokenizer = AutoTokenizer.from_pretrained("scfengv/TVL_GeneralLayerClassifier")
10
+
11
+ inputs = tokenizer("地震", return_tensors = "pt")
12
+
13
+ with torch.no_grad():
14
+ logits = model(**inputs).logits
15
+
16
+ predicted_class_id = logits.argmax().item()
17
+ print(f"Predicted class: {predicted_class_id}")