Python 库自动化 NLP 数据标注,用 LLM 智能识别和增强文本,显著降低人工标注成本。
Autolabel 是一个 Python 库,用于使用任何你选择的大型语言模型(LLM)来标签、清理和丰富文本数据集。
查看我们的技术报告,了解 RefuelLLM-v2 在我们基准测试上的性能。你可以按照以下步骤自己复制基准测试。
cd autolabel/benchmark
curl https://autolabel-benchmarking.s3.us-west-2.amazonaws.com/data.zip -o data.zip
unzip data.zip
python benchmark.py --model $model --base_dir benchmark-results
python results.py --eval_dir benchmark-results
cat results.csv
你可以通过用需要基准测试的模型名称替换 $model 来对相关模型进行基准测试。如果它是一个 API 托管模型,如 gpt-3.5-turbo、gpt-4-1106-preview、claude-3-opus-20240229、gemini-1.5-pro-preview-0409 或其他 Autolabel 支持的模型,只需写下模型的名称即可。如果要基准测试的模型是 vLLM 支持的模型,那么传递相应模型的本地路径或 huggingface 路径。这将使用所有模型的相同提示词来运行基准测试。
results.csv 会包含作为行的每个被基准测试的模型。查看 benchmark/results.csv 了解示例。
Autolabel 为数据标签提供了一个简单的 3 步流程:
让我们假设我们正在构建一个 ML 模型来分析电影评论的情感分析。我们有一个电影评论数据集,希望先进行标签标注。对于这种情况,以下是示例数据集和配置会是什么样子:
{
"task_name": "MovieSentimentReview",
"task_type": "classification",
"model": {
"provider": "openai",
"name": "gpt-3.5-turbo"
},
"dataset": {
"label_column": "label",
"delimiter": ","
},
"prompt": {
"task_guidelines": "You are an expert at analyzing the sentiment of movie reviews. Your job is to classify the provided movie review into one of the following labels: {labels}",
"labels": [
"positive",
"negative",
"neutral"
],
"few_shot_examples": [
{
"example": "I got a fairly uninspired stupid film about how human industry is bad for nature.",
"label": "negative"
},
{
"example": "I loved this movie. I found it very heart warming to see Adam West, Burt Ward, Frank Gorshin, and Julie Newmar together again.",
"label": "positive"
},
{
"example": "This movie will be played next week at the Chinese theater.",
"label": "neutral"
}
],
"example_template": "Input: {example}\nOutput: {label}"
}
}
初始化标签代理并将配置传递给它:
from autolabel import LabelingAgent, AutolabelDataset
agent = LabelingAgent(config='config.json')
预览将发送给 LLM 的示例提示:
ds = AutolabelDataset('dataset.csv', config = config)
agent.plan(ds)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100/100 0:00:00 0:00:00
┌──────────────────────────┬─────────┐
│ Total Estimated Cost │ $0.538 │
│ Number of Examples │ 200 │
│ Average cost per example │ 0.00269 │
└──────────────────────────┴─────────┘
─────────────────────────────────────────
Prompt Example:
You are an expert at analyzing the sentiment of movie reviews. Your job is to classify the provided movie review into one of the following labels: [positive, negative, neutral]
Some examples with their output answers are provided below:
Example: I got a fairly uninspired stupid film about how human industry is bad for nature.
Output:
negative
Example: I loved this movie. I found it very heart warming to see Adam West, Burt Ward, Frank Gorshin, and Julie Newmar together again.
Output:
positive
Example: This movie will be played next week at the Chinese theater.
Output:
neutral
Now I want you to label the following example:
Input: A rare exception to the rule that great literature makes disappointing films.
Output:
─────────────────────────────────────────────────────────────────────────────────────────
最后,我们可以对数据集的子集或全部运行标签标注:
ds = agent.run(ds)
输出数据帧包含标签列:
ds.df.head()
text ... MovieSentimentReview_llm_label
0 I was very excited about seeing this film, ant... ... negative
1 Serum is about a crazy doctor that finds a ser... ... negative
4 I loved this movie. I knew it would be chocked... ... positive
...
Refuel 为标签标注和置信度估计提供开源 LLM 的托管访问。这很有用,因为你可以为标签任务校准一个置信度阈值,然后将置信度较低的标签路由给人工,同时仍然为置信度较高的示例获得自动标签的好处。
为了使用 Refuel 托管的 LLM,你可以在此请求访问。
查看我们的公开路线图了解 Autolabel 库的正在进行和计划中的改进。
我们始终在寻求来自社区的建议和贡献。加入 Discord 上的讨论或在 Github 上开启一个 issue 来报告 bug 和请求功能。
Autolabel 是一个快速发展的项目。我们欢迎所有形式的贡献 - bug 报告、pull request 和改进库的想法。