AutoTrain 文档
分词分类
并获得增强的文档体验
开始使用
分词分类
分词分类是分类序列中每个词符的任务。 这可以用于命名实体识别 (NER)、词性 (POS) 标注等等。 准备好正确格式的数据,只需点击几下,您最先进的模型即可投入生产使用。
数据格式
数据应为以下 CSV 格式
tokens,tags
"['I', 'love', 'Paris']","['O', 'O', 'B-LOC']"
"['I', 'live', 'in', 'New', 'York']","['O', 'O', 'O', 'B-LOC', 'I-LOC']"
.
.
.
或者您也可以使用 JSONL 格式
{"tokens": ["I", "love", "Paris"],"tags": ["O", "O", "B-LOC"]}
{"tokens": ["I", "live", "in", "New", "York"],"tags": ["O", "O", "O", "B-LOC", "I-LOC"]}
.
.
.
如您所见,CSV 文件中有两列。一列是词符 (tokens),另一列是标签 (tags)。这两列都是字符串化的列表! “tokens”列包含句子的词符,“tags”列包含每个词符的标签。
如果您的 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
来自 HuggingFace Hub 的示例数据集: conll2003
列
您的 CSV/JSONL 数据集必须有两列:tokens
和 tags
。
参数
class autotrain.trainers.token_classification.params.TokenClassificationParams
< 源代码 >( data_path: str = None model: str = 'bert-base-uncased' lr: float = 5e-05 epochs: int = 3 max_seq_length: int = 128 batch_size: int = 8 warmup_ratio: float = 0.1 gradient_accumulation: int = 1 optimizer: str = 'adamw_torch' scheduler: str = 'linear' weight_decay: float = 0.0 max_grad_norm: float = 1.0 seed: int = 42 train_split: str = 'train' valid_split: typing.Optional[str] = None tokens_column: str = 'tokens' tags_column: str = 'tags' logging_steps: int = -1 project_name: str = 'project-name' auto_find_batch_size: bool = False mixed_precision: typing.Optional[str] = None save_total_limit: int = 1 token: typing.Optional[str] = None push_to_hub: bool = False eval_strategy: str = 'epoch' username: typing.Optional[str] = None log: str = 'none' early_stopping_patience: int = 5 early_stopping_threshold: float = 0.01 )
参数
- data_path (str) — 数据集路径。
- model (str) — 要使用的模型名称。 默认值为 “bert-base-uncased”。
- lr (float) — 学习率。默认值为 5e-5。
- epochs (int) — 训练 epoch 数。默认值为 3。
- max_seq_length (int) — 最大序列长度。默认值为 128。
- batch_size (int) — 训练批次大小。默认值为 8。
- warmup_ratio (float) — 预热比例。默认值为 0.1。
- gradient_accumulation (int) — 梯度累积步数。默认值为 1。
- optimizer (str) — 要使用的优化器。默认值为 “adamw_torch”。
- scheduler (str) — 要使用的调度器。默认值为 “linear”。
- seed (int) — Random seed. Default is 42.
- train_split (str) — Name of the training split. Default is “train”.
- valid_split (Optional[str]) — 验证分割的名称。默认为 None。
- tokens_column (str) — tokens 列的名称。默认为 “tokens”。
- tags_column (str) — tags 列的名称。默认为 “tags”。
- logging_steps (int) — 日志记录之间的步数。默认为 -1。
- project_name (str) — 项目名称。默认为 “project-name”。
- auto_find_batch_size (bool) — 是否自动查找批次大小。默认为 False。
- mixed_precision (Optional[str]) — 混合精度设置 (fp16, bf16, 或 None)。默认为 None。
- save_total_limit (int) — 要保存的检查点总数。默认为 1。
- token (Optional[str]) — 用于身份验证的 Hub 令牌。默认为 None。
- push_to_hub (bool) — 是否将模型推送到 Hugging Face Hub。默认为 False。
- eval_strategy (str) — 评估策略。默认为 “epoch”。
- username (Optional[str]) — Hugging Face 用户名。默认为 None。
- log (str) — 用于实验跟踪的日志记录方法。默认为 “none”。
- early_stopping_patience (int) — 提前停止的耐心值。默认为 5。
- early_stopping_threshold (float) — 提前停止的阈值。默认为 0.01。
TokenClassificationParams 是用于 token 分类训练参数的配置类。