🚀 KeywordGen-v2模型
KeywordGen-v2是一款基于T5架构微调的模型,专门用于从文本中提取关键词。输入一段文本,模型就能输出与之相关的关键词,为信息提取提供便利。
🚀 快速开始
你可以直接使用文本生成管道来调用这个模型。使用时,为了获得最佳效果,请在输入文本前加上 "Keyword: "。
以下是使用Hugging Face Transformers库在Python中调用该模型的示例:
💻 使用示例
基础用法
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("mrutyunjay-patil/keywordGen-v2")
model = T5ForConditionalGeneration.from_pretrained("mrutyunjay-patil/keywordGen-v2")
input_sequence = "Keyword: I purchased the new Android smartphone last week and I've been thoroughly impressed. The display is incredibly vibrant and sharp, and the battery life is surprisingly good, easily lasting a full day with heavy usage."
input_ids = tokenizer.encode(input_sequence, return_tensors="pt")
outputs = model.generate(input_ids)
output_sequence = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(output_sequence)
高级用法
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("mrutyunjay-patil/keywordGen-v2")
model = T5ForConditionalGeneration.from_pretrained("mrutyunjay-patil/keywordGen-v2")
task_prefix = "Keyword: "
inputs = [
"Absolutely love this tablet. It has a clear, sharp screen and runs apps smoothly without any hiccups.",
"The headphones are fantastic with great sound quality, but the build quality could be better.",
"Bought this smartwatch last week, and I'm thrilled with its performance. Battery life is impressive.",
"This laptop exceeded my expectations. Excellent speed, plenty of storage, and light weight. Perfect for my needs.",
"The camera quality on this phone is exceptional. It captures detailed and vibrant photos. However, battery life is not the best."
]
for sample in inputs:
input_sequence = task_prefix + sample
input_ids = tokenizer.encode(input_sequence, return_tensors="pt")
outputs = model.generate(input_ids)
output_sequence = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sample, "\n --->", output_sequence)
✨ 主要特性
- 针对性微调:该模型 "KeywordGen-v2" 是 "KeywordGen" 系列的第二代产品,基于T5基础模型进行微调,专注于从文本输入中生成关键词,尤其擅长处理产品评论。
- 输出规范:模型输出的关键词长度在2到8个单词之间,能有效提取产品评论中的关键点或主题。
- 输入要求:当输入文本至少有2 - 3个句子时,模型性能更佳。
📚 详细文档
模型描述
"KeywordGen-v2" 是 "KeywordGen" 系列的第二个版本,基于T5基础模型微调而来,专门用于从文本输入中生成关键词,尤其侧重于产品评论。该模型能够从产品评论中提取关键点或主题,输出的关键词预计在2到8个单词之间。当输入文本至少有2 - 3个句子时,模型性能更佳。
训练情况
此模型在自定义数据集上进行训练,基础模型采用的是T5基础模型。
局限性和未来工作
和任何机器学习模型一样,这个关键词生成器的输出依赖于其训练数据。如果输入文本包含不适当或有偏见的内容,模型可能会生成相应的关键词。未来的模型迭代将致力于提高其鲁棒性和公平性,并尽量减少潜在的偏差。
📄 许可证
本项目采用Apache-2.0许可证。
属性 |
详情 |
模型类型 |
文本到文本生成 |
训练数据 |
自定义数据集 |
库名称 |
transformers |
标签 |
代码、关键词生成、英文、T5 |
⚠️ 重要提示
由于模型输出依赖训练数据,若输入文本包含不适当或有偏见的内容,模型可能生成相应关键词。
💡 使用建议
使用模型时,在输入文本前加上 "Keyword: " 可获得最佳效果。同时,输入文本至少为2 - 3个句子,模型性能更佳。