Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: cc-by-nc-3.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-3.0
|
| 3 |
+
base_model:
|
| 4 |
+
- clue/albert_chinese_tiny
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from transformers import AlbertForSequenceClassification, AutoTokenizer
|
| 10 |
+
import torch
|
| 11 |
+
|
| 12 |
+
# 加载模型和分词器
|
| 13 |
+
model_name = "./results/checkpoint-3118" # 中文ALBERT-Tiny(仅18MB)
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 15 |
+
model = AlbertForSequenceClassification.from_pretrained(model_name, num_labels=2)
|
| 16 |
+
|
| 17 |
+
# print(model)
|
| 18 |
+
def predict(text):
|
| 19 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=64)
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
outputs = model(**inputs)
|
| 22 |
+
print(outputs)
|
| 23 |
+
return torch.argmax(outputs.logits).item()
|
| 24 |
+
|
| 25 |
+
text = "1、消失的他"
|
| 26 |
+
|
| 27 |
+
pred = predict(text)
|
| 28 |
+
```
|