AutoTrain 文档

文本分类

您正在查看 主分支 版本,它需要从源代码安装. 如果您想要使用 pip 进行常规安装,请查看最新的稳定版本 (v0.8.8).
Hugging Face's logo
加入 Hugging Face 社区

并获得增强型文档体验

开始使用

文本分类

使用 AutoTrain 训练文本分类模型非常简单!准备好格式正确的数据,然后只需点击几下,您就可以训练一个最先进的模型,并在生产环境中使用它。

数据格式

让我们训练一个模型来对电影评论的情感进行分类。数据应该以以下 CSV 格式保存

text,target
"this movie is great",positive
"this movie is bad",negative
.
.
.

如您所见,CSV 文件中包含两列。一列是文本,另一列是标签。标签可以是任何字符串。在本例中,我们有两个标签:positivenegative。您可以根据需要添加任意数量的标签。

如果您的 CSV 文件很大,您可以将其划分为多个 CSV 文件,然后分别上传。请确保所有 CSV 文件中的列名相同。

使用 pandas 将 CSV 文件划分为多个文件的一种方法如下所示

import pandas as pd

# Set the chunk size
chunk_size = 1000
i = 1

# Open the CSV file and read it in chunks
for chunk in pd.read_csv('example.csv', chunksize=chunk_size):
    # Save each chunk to a new file
    chunk.to_csv(f'chunk_{i}.csv', index=False)
    i += 1

除了 CSV 文件之外,您还可以使用 JSONL 格式。JSONL 格式应如下所示

{"text": "this movie is great", "target": "positive"}
{"text": "this movie is bad", "target": "negative"}
.
.
.

您的 CSV 数据集必须包含两列:texttarget

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.