32 lines
987 B
Python
32 lines
987 B
Python
from transformers import pipeline
|
|
|
|
|
|
classifier = pipeline(
|
|
"zero-shot-classification",
|
|
model="./nlp_structbert_zero-shot-classification_chinese-large",
|
|
device="cpu",
|
|
max_length=512,
|
|
ignore_mismatched_sizes=True # 忽略维度不匹配警告
|
|
)
|
|
level1 = [
|
|
"食品", "电器", "洗护", "女装", "手机",
|
|
"健康", "男装", "美妆", "电脑", "运动",
|
|
"内衣", "母婴", "数码", "百货", "鞋包",
|
|
"办公", "家装", "饰品", "车品", "图书",
|
|
"生鲜", "家纺", "宠物", "奢品", "其它","药品"
|
|
]
|
|
|
|
|
|
def theBestAndLow(goods):
|
|
result = classifier(
|
|
goods,
|
|
candidate_labels=level1,
|
|
truncation=True # 显式指定截断策略
|
|
)
|
|
labels = result['labels']
|
|
scores = result['scores']
|
|
|
|
print("最高分标签:", labels[0], "得分:", scores[0])
|
|
print("最低分标签:", labels[-1], "得分:", scores[-1])
|
|
|
|
theBestAndLow( "宇宙超萌儿童辅食有机果蔬蝴蝶面210g 数量:1盒装:") |