File size: 953 Bytes
0ab7a78
 
 
 
 
 
af52f26
 
 
0ab7a78
 
 
 
 
 
f58ed19
0ab7a78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
license: cc-by-nc-3.0
base_model:
- clue/albert_chinese_tiny
---

这是一个用于识别小说章节名称的超轻量级模型,被用于从小说文本中提取章节名称。基于 albert_chinese_tiny。

仓库: [https://github.com/kingzcheung/chapterlm](https://github.com/kingzcheung/chapterlm)

```python
from transformers import AlbertForSequenceClassification, AutoTokenizer
import torch

# 加载模型和分词器
model_name = "rkingzhong/chapterlm"  # 中文ALBERT-Tiny(仅18MB)
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AlbertForSequenceClassification.from_pretrained(model_name, num_labels=2)

# print(model)
def predict(text):
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=64)
    with torch.no_grad():
        outputs = model(**inputs)
        print(outputs)
    return torch.argmax(outputs.logits).item()

text = "1、消失的他"

pred = predict(text)
```