摘要
摘要流水线对文本进行总结。此流水线运行一个 text2text 模型,用于抽象地创建输入文本的摘要。
示例
以下展示了使用此流水线的简单示例。
from txtai.pipeline import Summary
# Create and run pipeline
summary = Summary()
summary("Enter long, detailed text to summarize here")
请参阅下方链接以获取更详细的示例。
笔记本 | 描述 | |
---|---|---|
构建抽象文本摘要 | 运行抽象文本摘要 |
配置驱动示例
流水线可以使用 Python 或配置运行。流水线可以在配置中使用流水线的小写名称进行实例化。配置驱动的流水线通过工作流或API运行。
config.yml
# Create pipeline using lower case class name
summary:
# Run pipeline with workflow
workflow:
summary:
tasks:
- action: summary
通过工作流运行
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("summary", ["Enter long, detailed text to summarize here"]))
通过 API 运行
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"summary", "elements":["Enter long, detailed text to summarize here"]}'
方法
此流水线的 Python 文档。
__init__(path=None, quantize=False, gpu=True, model=None, **kwargs)
源代码位于 txtai/pipeline/text/summary.py
15 16 |
|
__call__(text, minlength=None, maxlength=None, workers=0)
对文本块运行摘要模型。
此方法支持字符串或列表形式的文本输入。如果输入是字符串,返回类型为文本。如果输入是列表,则返回一个文本列表,其中每行对应一个文本块。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
text
|
text|list |
必填 | |
minlength
|
摘要的最小长度 |
None
|
|
maxlength
|
摘要的最大长度 |
None
|
|
workers
|
用于处理数据的并发工作线程数,默认为 None |
0
|
返回值
类型 | 描述 |
---|---|
摘要文本 |
源代码位于 txtai/pipeline/text/summary.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|