我正在针对多类分类任务微调 BERT 模型。我的问题是我不知道如何向这些 Trainer 实例添加“提前停止”。有任何想法吗?
python neural-network deep-learning huggingface-transformers huggingface
我正在 Google colab 中使用该transformers
库,当我使用 Transformers 库中的 TrainingArguments 时,我收到以下代码的导入错误:
from transformers import TrainingArguments
training_args = TrainingArguments(
output_dir = "/content/our-model",
learning_rate=2e-5,
per_device_train_batch_size= 64,
per_device_eval_batch_size = 16,
num_train_epochs = 2,
weight_decay = 0.01,
evaluation_strategy = "epoch",
save_strategy = "epoch",
load_best_model_at_end = True,
push_to_hub = False
)
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
<ipython-input-28-0518ea5ff407> in <cell line: 2>()
1 from transformers import TrainingArguments
----> 2 training_args = TrainingArguments(
3 output_dir = "/content/our-model",
4 learning_rate=2e-5,
5 per_device_train_batch_size= 64,
4 frames
/usr/local/lib/python3.10/dist-packages/transformers/training_args.py in _setup_devices(self)
1670 if not is_sagemaker_mp_enabled():
1671 …
Run Code Online (Sandbox Code Playgroud) 我正在研究在不同模型上使用 PEFT 的几个不同 示例。该LoraConfig
对象包含一个target_modules
数组。在一些示例中,目标模块是["query_key_value"]
,有时是["q", "v"]
,有时是其他。
我不太明白目标模块的值来自哪里。我应该在模型页面的哪个位置查看 LoRA 适配模块是什么?
一个示例(针对型号 Falcon 7B):
peft_config = LoraConfig(
lora_alpha=lora_alpha,
lora_dropout=lora_dropout,
r=lora_r,
bias="none",
task_type="CAUSAL_LM",
target_modules=[
"query_key_value",
"dense",
"dense_h_to_4h",
"dense_4h_to_h",
]
Run Code Online (Sandbox Code Playgroud)
另一个例子(对于型号 Opt-6.7B):
config = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q_proj", "v_proj"],
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM"
)
Run Code Online (Sandbox Code Playgroud)
还有另一个(对于型号 Flan-T5-xxl):
lora_config = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q", "v"],
lora_dropout=0.05,
bias="none",
task_type=TaskType.SEQ_2_SEQ_LM
)
Run Code Online (Sandbox Code Playgroud) 如何将 HuggingFace 数据集写入磁盘?
我使用 JSONL 文件制作了自己的 HuggingFace 数据集:
数据集({ 特征: ['id', 'text'], num_rows: 18 })
我想将数据集保存到磁盘。
有没有更好的方法来做到这一点?或者,是使用 joblib 或 pickle 等通用库的唯一选择吗?
当我尝试运行此存储库的快速启动笔记本时,出现错误。我该如何修复它?我已经使用 pip 安装了。ModuleNotFoundError: No module named 'huggingface_hub.snapshot_download'
huggingface_hub
编译以下单元格后出现错误:
!CUDA_VISIBLE_DEVICES=0 python -u ../scripts/main.py --summarizer gpt3_summarizer --controller longformer_classifier longformer_classifier --loader alignment coherence --controller-load-dir emnlp22_re3_data/ckpt/relevance_reranker emnlp22_re3_data/ckpt/coherence_reranker --controller-model-string allenai/longformer-base-4096 allenai/longformer-base-4096 --save-outline-file output/outline0.pkl --save-complete-file output/complete_story0.pkl --log-file output/story0.log
Run Code Online (Sandbox Code Playgroud)
这是整个输出:
Traceback (most recent call last):
File "../scripts/main.py", line 20, in <module>
from story_generation.edit_module.entity import *
File "/home/jovyan/emnlp22-re3-story-generation/story_generation/edit_module/entity.py", line 20, in <module>
from story_generation.common.util import *
File "/home/jovyan/emnlp22-re3-story-generation/story_generation/common/util.py", line 13, in <module>
from sentence_transformers import SentenceTransformer
File "/opt/conda/lib/python3.8/site-packages/sentence_transformers/__init__.py", line 3, in <module> …
Run Code Online (Sandbox Code Playgroud) 我正在使用 llama-index 基于文档创建一个非常简单的问答应用程序。此前,我曾将其与 OpenAI 一起使用。现在我想尝试不使用外部 API,因此我尝试此链接中的Hugging Face 示例。
它在链接的示例中说:“请注意,为了获得完全私人的体验,还需要设置本地嵌入模型(此处的示例)。” 我假设下面给出的示例是所引用的示例。因此,很自然地,我尝试复制该示例(此处为更完整的示例)。
这是我的代码:
from pathlib import Path
import gradio as gr
import sys
import logging
import os
from llama_index.llms import HuggingFaceLLM
from llama_index.prompts.prompts import SimpleInputPrompt
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
from llama_index import SimpleDirectoryReader, VectorStoreIndex, ServiceContext, load_index_from_storage, StorageContext
storage_path = "storage/"
docs_path="docs"
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
#max_chunk_overlap = 20
chunk_overlap_ratio = 0.1
chunk_size_limit = 600
#prompt_helper = PromptHelper(max_input_size, num_outputs, chunk_overlap_ratio, chunk_size_limit=chunk_size_limit)
system_prompt = """<|SYSTEM|># StableLM Tuned …
Run Code Online (Sandbox Code Playgroud) python huggingface-transformers huggingface llama-index large-language-model
由于 SSL 证书错误,我在从 HuggingFace 加载预训练的 BERT 模型时遇到以下问题。
SSLError: HTTPSConnectionPool(host='huggingface.co', port=443): 超过最大重试次数,网址为:/dslim/bert-base-NER/resolve/main/tokenizer_config.json (由 SSLError(SSLCertVerificationError(1, '[ SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:证书链中的自签名证书 (_ssl.c:1108)')))
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
Run Code Online (Sandbox Code Playgroud)
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")
Run Code Online (Sandbox Code Playgroud)
我希望在 Windows 上的 jupyter 实验室中运行代码时下载预先训练的模型。
python-3.x bert-language-model huggingface-transformers huggingface-tokenizers huggingface
有没有办法从huggingface 的meta-llama/Llama-2-13b-chat-hf 获取句子嵌入?
\n模特链接:https://huggingface.co/meta-llama/Llama-2-13b-chat-hf
\n我尝试使用拥抱面孔中的 transfomer.Automodel 模块来获取嵌入,但结果看起来并不符合预期。实施方式参见以下链接。参考:https ://github.com/Muennighoff/sgpt#ametry-semantic-search-be\xc2\xa0
\nartificial-intelligence huggingface-transformers huggingface large-language-model llama
我总是收到“在一张或多张图像中检测到潜在的 NSFW 内容。将返回黑色图像。使用不同的提示和/或种子重试。” 使用稳定扩散时出错,即使使用 Huggingface 上给出的代码:
import torch
from torch import autocast
from diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"
device = "cuda"
token = 'MY TOKEN'
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=token)
pipe = pipe.to(device)
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt, guidance_scale=7.5).images[0]
image.save("astronaut_rides_horse.png")
Run Code Online (Sandbox Code Playgroud) 我目前将我的教练设置为:
\ntraining_args = TrainingArguments(\n output_dir=f"./results_{model_checkpoint}",\n evaluation_strategy="epoch",\n learning_rate=5e-5,\n per_device_train_batch_size=4,\n per_device_eval_batch_size=4,\n num_train_epochs=2,\n weight_decay=0.01,\n push_to_hub=True,\n save_total_limit = 1,\n resume_from_checkpoint=True,\n)\n\ntrainer = Trainer(\n model=model,\n args=training_args,\n train_dataset=tokenized_qa["train"],\n eval_dataset=tokenized_qa["validation"],\n tokenizer=tokenizer,\n data_collator=DataCollatorForMultipleChoice(tokenizer=tokenizer),\n compute_metrics=compute_metrics\n)\n
Run Code Online (Sandbox Code Playgroud)\n训练结束后,我的output_dir
I 有训练师保存的几个文件:
[\'README.md\',\n \'tokenizer.json\',\n \'training_args.bin\',\n \'.git\',\n \'.gitignore\',\n \'vocab.txt\',\n \'config.json\',\n \'checkpoint-5000\',\n \'pytorch_model.bin\',\n \'tokenizer_config.json\',\n \'special_tokens_map.json\',\n \'.gitattributes\']\n
Run Code Online (Sandbox Code Playgroud)\n从文档来看,似乎resume_from_checkpoint
将从最后一个检查点继续训练模型:
resume_from_checkpoint (str or bool, optional) \xe2\x80\x94 If a str, local path to a saved checkpoint as saved by a previous instance of Trainer. If a bool and equals True, …
huggingface ×10
python ×5
nlp ×2
fine-tuning ×1
importerror ×1
llama ×1
llama-index ×1
peft ×1
python-3.x ×1
pytorch ×1