国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

HuggingFace簡明教程

這篇具有很好參考價(jià)值的文章主要介紹了HuggingFace簡明教程。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

視頻鏈接:HuggingFace簡明教程,BERT中文模型實(shí)戰(zhàn)示例.NLP預(yù)訓(xùn)練模型,Transformers類庫,datasets類庫快速入門._嗶哩嗶哩_bilibili

1.huggingface簡介與安裝

什么是huggingface?huggingface是一個(gè)開源社區(qū),它提供了先進(jìn)的NLP模型,數(shù)據(jù)集,以及其他便利的工具。

數(shù)據(jù)集:Hugging Face – The AI community building the future.?

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

這些數(shù)據(jù)集可以根據(jù)任務(wù)、語言等來分類

模型:Models - Hugging Face?

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

官方文檔:?Hugging Face - Documentation?

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

?主要的模型:

? ? ? ? 自回歸:GPT2、Transformer-XL、XLNet

? ? ? ? 自編碼:BERT、ALBERT、RoBERTa、ELECTRA

? ? ? ? Seq2Seq:BART、Pegasus、T5

安裝環(huán)境:

? ? ? ? 前置環(huán)境:python、pytorch安裝

? ? ? ? 安裝transformers、datasets包:

#安裝transformers
#pip安裝
pip install transformers

#conda安裝
conda install -c huggingface transformers

#安裝datasets
#pip安裝
pip install datasets

#conda安裝
conda install -c huggingface -c conda-forge datasets

推薦使用pip進(jìn)行安裝

2.使用字典和分詞工具

加載tokenizer,準(zhǔn)備語料

????????在加載tokenizer的時(shí)候要傳一個(gè)name,這個(gè)name與模型的name相一致,所以一個(gè)模型對(duì)應(yīng)一個(gè)tokenizer

from transformers import BertTokenizer

#加載預(yù)訓(xùn)練字典和分詞方法
tokenizer = BertTokenizer.from_pretrained(
    pretrained_model_name_or_path='bert-base-chinese',
    cache_dir=None,
    force_download=False,
)

sents = [
    '選擇珠江花園的原因就是方便。',
    '筆記本的鍵盤確實(shí)爽。',
    '房間太小。其他的都一般。',
    '今天才知道這書還有第6卷,真有點(diǎn)郁悶.',
    '機(jī)器背面似乎被撕了張什么標(biāo)簽,殘膠還在。',
]

tokenizer, sents

簡單的編碼

一次編碼兩個(gè)句子,text_pair是可以不傳的,如果不傳的話就是一次編碼一個(gè)句子

#編碼兩個(gè)句子
out = tokenizer.encode(
    text=sents[0],
    text_pair=sents[1],

    #當(dāng)句子長度大于max_length時(shí),截?cái)?    truncation=True,

    #一律補(bǔ)pad到max_length長度
    padding='max_length',
    add_special_tokens=True,
    max_length=30,
    return_tensors=None,# 默認(rèn)返回list
)

print(out)

tokenizer.decode(out)
 

增強(qiáng)的編碼函數(shù)

#增強(qiáng)的編碼函數(shù)
out = tokenizer.encode_plus(
    text=sents[0],
    text_pair=sents[1],

    #當(dāng)句子長度大于max_length時(shí),截?cái)?    truncation=True,

    #一律補(bǔ)零到max_length長度
    padding='max_length',
    max_length=30,
    add_special_tokens=True,

    #可取值tf,pt,np,默認(rèn)為返回list
    return_tensors=None,

    #返回token_type_ids
    return_token_type_ids=True,

    #返回attention_mask
    return_attention_mask=True,

    #返回special_tokens_mask 特殊符號(hào)標(biāo)識(shí)
    return_special_tokens_mask=True,

    #返回offset_mapping 標(biāo)識(shí)每個(gè)詞的起止位置,這個(gè)參數(shù)只能BertTokenizerFast使用
    #return_offsets_mapping=True,

    #返回length 標(biāo)識(shí)長度
    return_length=True,
)

增強(qiáng)編碼的結(jié)果:

#input_ids 就是編碼后的詞
#token_type_ids 第一個(gè)句子和特殊符號(hào)的位置是0,第二個(gè)句子的位置是1
#special_tokens_mask 特殊符號(hào)的位置是1,其他位置是0
#attention_mask pad的位置是0,其他位置是1
#length 返回句子長度
for k, v in out.items():
    print(k, ':', v)

tokenizer.decode(out['input_ids'])

?huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

?批量編碼句子

上述方式是一次編碼一個(gè)或者一對(duì)句子,但是實(shí)際操作中需要批量編碼句子。這里編碼的是一個(gè)一個(gè)的句子,而不是一對(duì)一對(duì)的句子

#批量編碼句子
out = tokenizer.batch_encode_plus(
    batch_text_or_text_pairs=[sents[0], sents[1]],
    add_special_tokens=True,

    #當(dāng)句子長度大于max_length時(shí),截?cái)?    truncation=True,

    #一律補(bǔ)零到max_length長度
    padding='max_length',
    max_length=15,

    #可取值tf,pt,np,默認(rèn)為返回list
    return_tensors=None,

    #返回token_type_ids
    return_token_type_ids=True,

    #返回attention_mask
    return_attention_mask=True,

    #返回special_tokens_mask 特殊符號(hào)標(biāo)識(shí)
    return_special_tokens_mask=True,

    #返回offset_mapping 標(biāo)識(shí)每個(gè)詞的起止位置,這個(gè)參數(shù)只能BertTokenizerFast使用
    #return_offsets_mapping=True,

    #返回length 標(biāo)識(shí)長度
    return_length=True,
)

批量編碼的結(jié)果:

#input_ids 就是編碼后的詞
#token_type_ids 第一個(gè)句子和特殊符號(hào)的位置是0,第二個(gè)句子的位置是1
#special_tokens_mask 特殊符號(hào)的位置是1,其他位置是0
#attention_mask pad的位置是0,其他位置是1
#length 返回句子長度
for k, v in out.items():
    print(k, ':', v)

tokenizer.decode(out['input_ids'][0]), tokenizer.decode(out['input_ids'][1])

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

批量成對(duì)編碼

傳入的list中是一個(gè)一個(gè)的tuple,tuple中是一對(duì)句子

#批量編碼成對(duì)的句子
out = tokenizer.batch_encode_plus(
    batch_text_or_text_pairs=[(sents[0], sents[1]), (sents[2], sents[3])],
    add_special_tokens=True,

    #當(dāng)句子長度大于max_length時(shí),截?cái)?    truncation=True,

    #一律補(bǔ)零到max_length長度
    padding='max_length',
    max_length=30,

    #可取值tf,pt,np,默認(rèn)為返回list
    return_tensors=None,

    #返回token_type_ids
    return_token_type_ids=True,

    #返回attention_mask
    return_attention_mask=True,

    #返回special_tokens_mask 特殊符號(hào)標(biāo)識(shí)
    return_special_tokens_mask=True,

    #返回offset_mapping 標(biāo)識(shí)每個(gè)詞的起止位置,這個(gè)參數(shù)只能BertTokenizerFast使用
    #return_offsets_mapping=True,

    #返回length 標(biāo)識(shí)長度
    return_length=True,
)

批量成對(duì)編碼結(jié)果:

#input_ids 就是編碼后的詞
#token_type_ids 第一個(gè)句子和特殊符號(hào)的位置是0,第二個(gè)句子的位置是1
#special_tokens_mask 特殊符號(hào)的位置是1,其他位置是0
#attention_mask pad的位置是0,其他位置是1
#length 返回句子長度
for k, v in out.items():
    print(k, ':', v)

tokenizer.decode(out['input_ids'][0])

?字典操作

操作tokenizer中的字典,當(dāng)前的字典以一個(gè)字為一個(gè)詞

#獲取字典
zidian = tokenizer.get_vocab()

type(zidian), len(zidian), '月光' in zidian,

?huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#添加新詞
tokenizer.add_tokens(new_tokens=['月光', '希望'])

#添加新符號(hào)
tokenizer.add_special_tokens({'eos_token': '[EOS]'})

zidian = tokenizer.get_vocab()

type(zidian), len(zidian), zidian['月光'], zidian['[EOS]']

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

?編碼新詞:

#編碼新添加的詞
out = tokenizer.encode(
    text='月光的新希望[EOS]',
    text_pair=None,

    #當(dāng)句子長度大于max_length時(shí),截?cái)?    truncation=True,

    #一律補(bǔ)pad到max_length長度
    padding='max_length',
    add_special_tokens=True,
    max_length=8,
    return_tensors=None,
)

print(out)

tokenizer.decode(out)

3.數(shù)據(jù)集操作

加載數(shù)據(jù)集

以情感分類數(shù)據(jù)集為例

from datasets import load_dataset

#加載數(shù)據(jù)
dataset = load_dataset(path='seamew/ChnSentiCorp')

dataset

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#查看一個(gè)數(shù)據(jù)
dataset[0]

??排序和打亂

#sort

#未排序的label是亂序的
print(dataset['label'][:10])

#排序之后label有序了
sorted_dataset = dataset.sort('label')
print(sorted_dataset['label'][:10])
print(sorted_dataset['label'][-10:])

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#shuffle

#打亂順序
shuffled_dataset = sorted_dataset.shuffle(seed=42)

shuffled_dataset['label'][:10]

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

選擇和過濾

#select
dataset.select([0, 10, 20, 30, 40, 50])

?huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#filter
def f(data):
    return data['text'].startswith('選擇')


start_with_ar = dataset.filter(f)

len(start_with_ar), start_with_ar['text']

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

切分和分桶

#train_test_split, 切分訓(xùn)練集和測(cè)試集
dataset.train_test_split(test_size=0.1)

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#shard
#把數(shù)據(jù)切分到4個(gè)桶中,均勻分配
dataset.shard(num_shards=4, index=0)

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

列操作和類型轉(zhuǎn)換

#rename_column
dataset.rename_column('text', 'textA')

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#remove_columns
dataset.remove_columns(['text'])

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

#set_format
dataset.set_format(type='torch', columns=['label'])

dataset[0]

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

?map函數(shù)

對(duì)數(shù)據(jù)集中的每一條數(shù)據(jù)都做函數(shù)f操作

#map
def f(data):
    data['text'] = 'My sentence: ' + data['text']
    return data


datatset_map = dataset.map(f)

datatset_map['text'][:5]

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

保存和加載

#保存數(shù)據(jù)集到磁盤
dataset.save_to_disk(dataset_dict_path='./data/ChnSentiCorp')

#從磁盤加載數(shù)據(jù)
from datasets import load_from_disk

dataset = load_from_disk('./data/ChnSentiCorp')

導(dǎo)出和保存為其他格式

#導(dǎo)出為csv格式
dataset = load_dataset(path='seamew/ChnSentiCorp', split='train')
dataset.to_csv(path_or_buf='./data/ChnSentiCorp.csv')

#加載csv格式數(shù)據(jù)
csv_dataset = load_dataset(path='csv',
                           data_files='./data/ChnSentiCorp.csv',
                           split='train')

#導(dǎo)出為json格式
dataset = load_dataset(path='seamew/ChnSentiCorp', split='train')
dataset.to_json(path_or_buf='./data/ChnSentiCorp.json')

#加載json格式數(shù)據(jù)
json_dataset = load_dataset(path='json',
                            data_files='./data/ChnSentiCorp.json',
                            split='train')

4.使用評(píng)價(jià)函數(shù)

查看可用的評(píng)價(jià)指標(biāo)

from datasets import list_metrics

#列出評(píng)價(jià)指標(biāo)
metrics_list = list_metrics()

len(metrics_list), metrics_list

?查看該指標(biāo)的說明文檔

可以按照評(píng)價(jià)指標(biāo)的說明文檔中的示例代碼來使用該指標(biāo)

from datasets import load_metric

#加載一個(gè)評(píng)價(jià)指標(biāo)
metric = load_metric('glue', 'mrpc')

print(metric.inputs_description)

計(jì)算一個(gè)評(píng)價(jià)指標(biāo)

#計(jì)算一個(gè)評(píng)價(jià)指標(biāo)
predictions = [0, 1, 0]
references = [0, 1, 1]

final_score = metric.compute(predictions=predictions, references=references)

final_score

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

5.使用pipline函數(shù)

pipeline提供了一些不需要訓(xùn)練就可以執(zhí)行一些nlp任務(wù)的模型,實(shí)用價(jià)值不高

情感分類

from transformers import pipeline

#文本分類
classifier = pipeline("sentiment-analysis")

result = classifier("I hate you")[0]
print(result)

result = classifier("I love you")[0]
print(result)

?閱讀理解

from transformers import pipeline

#閱讀理解
question_answerer = pipeline("question-answering")

context = r"""
Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a 
question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune 
a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
"""

result = question_answerer(question="What is extractive question answering?",
                           context=context)
print(result)

result = question_answerer(
    question="What is a good example of a question answering dataset?",
    context=context)

print(result)

完形填空

from transformers import pipeline

#完形填空
unmasker = pipeline("fill-mask")

from pprint import pprint

sentence = 'HuggingFace is creating a <mask> that the community uses to solve NLP tasks.'

unmasker(sentence)

文本生成

from transformers import pipeline

#文本生成
text_generator = pipeline("text-generation")

text_generator("As far as I am concerned, I will",
               max_length=50,
               do_sample=False)

命名實(shí)體識(shí)別

from transformers import pipeline

#命名實(shí)體識(shí)別
ner_pipe = pipeline("ner")

sequence = """Hugging Face Inc. is a company based in New York City. Its headquarters are in DUMBO,
therefore very close to the Manhattan Bridge which is visible from the window."""

for entity in ner_pipe(sequence):
    print(entity)

文本摘要

from transformers import pipeline

#文本總結(jié)
summarizer = pipeline("summarization")

ARTICLE = """ New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County, New York.
A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.
Only 18 days after that marriage, she got hitched yet again. Then, Barrientos declared "I do" five more times, sometimes only within two weeks of each other.
In 2010, she married once more, this time in the Bronx. In an application for a marriage license, she stated it was her "first and only" marriage.
Barrientos, now 39, is facing two criminal counts of "offering a false instrument for filing in the first degree," referring to her false statements on the
2010 marriage license application, according to court documents.
Prosecutors said the marriages were part of an immigration scam.
On Friday, she pleaded not guilty at State Supreme Court in the Bronx, according to her attorney, Christopher Wright, who declined to comment further.
After leaving court, Barrientos was arrested and charged with theft of service and criminal trespass for allegedly sneaking into the New York subway through an emergency exit, said Detective
Annette Markowski, a police spokeswoman. In total, Barrientos has been married 10 times, with nine of her marriages occurring between 1999 and 2002.
All occurred either in Westchester County, Long Island, New Jersey or the Bronx. She is believed to still be married to four men, and at one time, she was married to eight men at once, prosecutors say.
Prosecutors said the immigration scam involved some of her husbands, who filed for permanent residence status shortly after the marriages.
Any divorces happened only after such filings were approved. It was unclear whether any of the men will be prosecuted.
The case was referred to the Bronx District Attorney\'s Office by Immigration and Customs Enforcement and the Department of Homeland Security\'s
Investigation Division. Seven of the men are from so-called "red-flagged" countries, including Egypt, Turkey, Georgia, Pakistan and Mali.
Her eighth husband, Rashid Rajput, was deported in 2006 to his native Pakistan after an investigation by the Joint Terrorism Task Force.
If convicted, Barrientos faces up to four years in prison.  Her next court appearance is scheduled for May 18.
"""

summarizer(ARTICLE, max_length=130, min_length=30, do_sample=False)

翻譯

from transformers import pipeline

#翻譯
translator = pipeline("translation_en_to_de")

sentence = "Hugging Face is a technology company based in New York and Paris"

translator(sentence, max_length=40)

trainer API

加載分詞工具

from transformers import AutoTokenizer

#加載分詞工具
tokenizer = AutoTokenizer.from_pretrained('bert-base-cased')

定義數(shù)據(jù)集

from datasets import load_dataset
from datasets import load_from_disk

#加載數(shù)據(jù)集
#從網(wǎng)絡(luò)加載
#datasets = load_dataset(path='glue', name='sst2')

#從本地磁盤加載數(shù)據(jù)
datasets = load_from_disk('./data/glue_sst2')


#分詞
def f(data):
    return tokenizer(
        data['sentence'],
        padding='max_length',
        truncation=True,
        max_length=30,
    )


datasets = datasets.map(f, batched=True, batch_size=1000, num_proc=4)

#取數(shù)據(jù)子集,否則數(shù)據(jù)太多跑不動(dòng)
dataset_train = datasets['train'].shuffle().select(range(1000))
dataset_test = datasets['validation'].shuffle().select(range(200))

del datasets

dataset_train

加載模型

from transformers import AutoModelForSequenceClassification

#加載模型
model = AutoModelForSequenceClassification.from_pretrained('bert-base-cased',
                                                           num_labels=2)

print(sum([i.nelement() for i in model.parameters()]) / 10000) # 查看模型參數(shù)數(shù)量

定義評(píng)價(jià)函數(shù)

import numpy as np
from datasets import load_metric
from transformers.trainer_utils import EvalPrediction

#加載評(píng)價(jià)函數(shù)
metric = load_metric('accuracy')


#定義評(píng)價(jià)函數(shù)
def compute_metrics(eval_pred):
    logits, labels = eval_pred
    logits = logits.argmax(axis=1)
    return metric.compute(predictions=logits, references=labels)


#模擬測(cè)試輸出
eval_pred = EvalPrediction(
    predictions=np.array([[0, 1], [2, 3], [4, 5], [6, 7]]),
    label_ids=np.array([1, 1, 1, 1]),
)

compute_metrics(eval_pred)

定義訓(xùn)練器并測(cè)試

from transformers import TrainingArguments, Trainer

#初始化訓(xùn)練參數(shù)
args = TrainingArguments(output_dir='./output_dir', evaluation_strategy='epoch')
args.num_train_epochs = 1
args.learning_rate = 1e-4
args.weight_decay = 1e-2
args.per_device_eval_batch_size = 32
args.per_device_train_batch_size = 16

#初始化訓(xùn)練器
trainer = Trainer(
    model=model,
    args=args,
    train_dataset=dataset_train,
    eval_dataset=dataset_test,
    compute_metrics=compute_metrics,
)

#評(píng)價(jià)模型
trainer.evaluate()

huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

模型未訓(xùn)練前的準(zhǔn)確率是0.49

#訓(xùn)練
trainer.train()

?huggingface,nlp學(xué)習(xí)筆記,自然語言處理,人工智能

?訓(xùn)練一個(gè)epoch之后的準(zhǔn)確率為0.8文章來源地址http://www.zghlxwxcb.cn/news/detail-822415.html

保存模型參數(shù)

#保存模型
trainer.save_model(output_dir='./output_dir')

使用保存的模型參數(shù)

定義測(cè)試數(shù)據(jù)集

import torch


def collate_fn(data):
    label = [i['label'] for i in data]
    input_ids = [i['input_ids'] for i in data]
    token_type_ids = [i['token_type_ids'] for i in data]
    attention_mask = [i['attention_mask'] for i in data]

    label = torch.LongTensor(label)
    input_ids = torch.LongTensor(input_ids)
    token_type_ids = torch.LongTensor(token_type_ids)
    attention_mask = torch.LongTensor(attention_mask)

    return label, input_ids, token_type_ids, attention_mask


#數(shù)據(jù)加載器
loader_test = torch.utils.data.DataLoader(dataset=dataset_test,
                                          batch_size=4,
                                          collate_fn=collate_fn,
                                          shuffle=True,
                                          drop_last=True)

for i, (label, input_ids, token_type_ids,
        attention_mask) in enumerate(loader_test):
    break

label, input_ids, token_type_ids, attention_mask

測(cè)試

import torch


#測(cè)試
def test():
    #加載參數(shù)
    model.load_state_dict(torch.load('./output_dir/pytorch_model.bin'))

    model.eval()

    #運(yùn)算
    out = model(input_ids=input_ids,
                token_type_ids=token_type_ids,
                attention_mask=attention_mask)

    #[4, 2] -> [4]
    out = out['logits'].argmax(dim=1)

    correct = (out == label).sum().item()

    return correct / len(label)


test()

到了這里,關(guān)于HuggingFace簡明教程的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Elasticsearch:使用 huggingface 模型的 NLP 文本搜索

    Elasticsearch:使用 huggingface 模型的 NLP 文本搜索

    本博文使用由 Elastic 博客 title 組成的簡單數(shù)據(jù)集在 Elasticsearch 中實(shí)現(xiàn) NLP 文本搜索。你將為博客文檔建立索引,并使用攝取管道生成文本嵌入。 通過使用 NLP 模型,你將使用自然語言在博客文檔上查詢文檔。 如果你還沒有安裝好自己的 Elasticsearch 及 Kibana,請(qǐng)參考如下的鏈接

    2024年02月07日
    瀏覽(16)
  • 使用 Docker 和 HuggingFace 實(shí)現(xiàn) NLP 文本情感分析應(yīng)用

    使用 Docker 和 HuggingFace 實(shí)現(xiàn) NLP 文本情感分析應(yīng)用

    在繼續(xù)分享“干燥、有趣”的向量數(shù)據(jù)庫實(shí)戰(zhàn)內(nèi)容之前,我們來聊一篇簡單有趣的內(nèi)容:如何使用 Docker 和 HuggingFace 現(xiàn)成的模型,快速實(shí)現(xiàn)一個(gè) NLP 文本情感分析應(yīng)用,支持中英文內(nèi)容的情感快速分析。 在這篇文章里,我們不需要準(zhǔn)備顯卡和語料,也不需要耐心等待“煉丹”

    2023年04月10日
    瀏覽(24)
  • 【NLP,Huggingface,Colab】使用 Trainer 訓(xùn)練模型,并保存模型參數(shù)

    【NLP,Huggingface,Colab】使用 Trainer 訓(xùn)練模型,并保存模型參數(shù)

    Colab 的使用 Huggingface 官網(wǎng)和一些基礎(chǔ)API 首先,建議 保存代碼到 VSCode ,這樣雙擊關(guān)鍵類, F12 可以進(jìn)入查看具體接口參數(shù)及其含義。 然后,建議 代碼在 Colab 運(yùn)行 ,第一個(gè)是有默認(rèn) GPU 資源,第二個(gè)是否則會(huì)產(chǎn)生各種 ConnectionError, OSError 等錯(cuò)誤… 重點(diǎn)可以看注釋。自行摸索了

    2024年02月13日
    瀏覽(23)
  • Docker入門簡明教程

    Docker入門簡明教程

    Docker 是基于 Go 語言實(shí)現(xiàn)的云開源項(xiàng)目,是基于 Linux 的多項(xiàng)開源技術(shù)提供高效、敏捷和輕量級(jí)的容器方案。創(chuàng)建于 2013 年初,自從開源后就受到了廣泛的關(guān)注,從長遠(yuǎn)的眼光來看,Docker 是未來虛擬化的一個(gè)發(fā)展的趨勢(shì)。帶來了更輕量快捷的的體驗(yàn),一臺(tái)主機(jī)可以同時(shí)運(yùn)行數(shù)千

    2024年01月23日
    瀏覽(20)
  • 【Verilator】 1 簡明教程

    【Verilator】 1 簡明教程

    我是 雪天魚 ,一名FPGA愛好者,研究方向是FPGA架構(gòu)探索和數(shù)字IC設(shè)計(jì)。 歡迎來關(guān)注我的B站賬號(hào),我將定期更新IC設(shè)計(jì)教程。 B站賬號(hào): 雪天魚 ,https://space.bilibili.com/397002941?spm_id_from=333.1007.0.0 先從GitHub下載實(shí)驗(yàn)代碼 以一個(gè)用SystemVerilog編寫的簡單ALU來作為DUT(device under test)

    2024年02月02日
    瀏覽(24)
  • SAP報(bào)表簡明教程

    SAP報(bào)表簡明教程

    SAP 報(bào)表簡明教程 ? 一、 報(bào)表需求,根據(jù)物料編碼和物料類型 查詢報(bào)表。用戶輸入界面要求如下: ? ? 二、 開始寫代碼。先進(jìn)入 TCODE:SE38 ,新建一個(gè)程序。 ? ?? 點(diǎn)擊創(chuàng)建按鈕,如下圖:? ? ? 輸入標(biāo)題,寫明 此程序的功能 作者,創(chuàng)建時(shí)間,點(diǎn)保存, ? ? 輸入自己事先建

    2024年02月04日
    瀏覽(18)
  • Husky使用簡明教程

    Husky 是一個(gè)流行的 Git 鉤子工具,用于在不同的 Git 操作(如提交和推送)前自動(dòng)運(yùn)行腳本。比如代碼格式化、靜態(tài)檢查等。這有助于保持代碼庫的質(zhì)量和一致性。本教程將詳細(xì)介紹 Husky 的原理、使用方式、配置方法以及如何在開發(fā)中集成 Husky。 Husky 原理 安裝 Husky 配置 Hus

    2024年04月10日
    瀏覽(21)
  • SSH 隧道簡明教程

    SSH 隧道簡明教程

    本章主要介紹了什么是 SSH 隧道以及如何使用 SSH 隧道,包括 SSH 隧道加密數(shù)據(jù)傳輸以及繞過防火墻。 SSH 隧道是 SSH 中的一種機(jī)制,它能夠?qū)⑵渌?TCP 端口的網(wǎng)絡(luò)數(shù)據(jù)通過 SSH 連接來轉(zhuǎn)發(fā),并且自動(dòng)提供了相應(yīng)的加密及解密服務(wù)。因?yàn)?SSH 為其他 TCP 鏈接提供了一個(gè)安全的通道來

    2024年02月06日
    瀏覽(20)
  • dig 簡明教程

    dig 簡明教程

    哈嘍大家好,我是咸魚 不知道大家在日常學(xué)習(xí)或者工作當(dāng)中用 dig 命令多不多 dig 是 Domain Information Groper 的縮寫,對(duì)于網(wǎng)絡(luò)管理員和在域名系統(tǒng)(DNS)領(lǐng)域工作的小伙伴來說,它是一個(gè)非常常見且有用的工具。 無論是簡單的 DNS 解析查找還是更高級(jí)的故障排除和分析, dig 都能夠

    2024年02月08日
    瀏覽(48)
  • mpack簡明教程

    mpack簡明教程

    本文先簡單介紹MessagePack的基本概念。 然后,介紹一個(gè)MessagePack C API - MPack的通常使用。 接著嘗試對(duì)MPack截?cái)鄶?shù)據(jù)的讀取。 注:本文完整代碼見倉庫。 如果你使用過C/C++的json庫,那么上手MessagePack是比較容易的。關(guān)于C/C++ Json庫的使用可見:C++ JSON庫的一般使用方法-CSDN博客。

    2024年02月20日
    瀏覽(39)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包