当前位置:网站首页>使用Huggingface在矩池云快速加载预训练模型和数据集
使用Huggingface在矩池云快速加载预训练模型和数据集
2022-06-21 11:31:00 【老表】
作为NLP领域的著名框架,Huggingface(HF)为社区提供了众多好用的预训练模型和数据集。本文介绍了在矩池云如何的快速上手,实践NLP模型。
1.环境
HF支持Pytorch,TensorFlow和Flax。您可以根据HF官方文档安装特点版本,也可以使用矩池云HuggingFace Pytorch镜像,快速启动。
如果使用其他镜像,你需要手动安装 transformers 和 datasets 两个包:
pip install transformers datasets
HF具体使用方式和代码请参考官方https://github.com/huggingface/transformers
2.预训练模型
2.1 预训练模型简介
HF拥有非常丰富的预训练模型,支持不同软件版本,可用于Pipeline和模型微调。除了从HF官方Model Hub下载预训练模型(可能耗时较长),矩池云提供了部分常用的预训练模型。访问路径:/public/model/nlp/
预训练模型名称(定时更新,也可联系矩池云小助手):
| 模型名称 |
|---|
| albert-base-v2 |
| bert-base-cased |
| bert-base-chinese |
| bert-base-uncased |
| bert-large-uncased |
| chinese-bert-wwm-ext |
| chinese-electra-180g-base-discriminator |
| chinese-roberta-wwm-ext |
| clip-vit-base-patch32 |
| code_trans_t5_small_program_synthese_transfer_learning_finetune |
| distilbart-cnn-12-6 |
| distilbert-base-uncased-finetuned-sst-2-english |
| distilgpt2 |
| gpt2-chinese-cluecorpussmall |
| gpt2 |
| roberta-base |
| t5-base |
| xlm-roberta-base |
2.2 预训练模型使用方法
首先需要将自己需要使用的预训练模型zip文件解压到矩池云网盘或者机器中其他目录(存到网盘后下次可以直接使用),使用模型时填入本地存储路径即可调用。
以使用albert-base-v2模型为例子:
解压
unzip /public/model/nlp/albert-base-v2.zip -d /mnt/
代码中使用
如果环境中没有transformers包,可以先pip install transformers安装。
from transformers import AutoModel
model = AutoModel.from_pretrained('/mnt/albert-base-v2')
# 注意 /mnt/albert-base-v2 是你解压后模型文件所在路径
3.数据集
3.1 数据集简介
数据集存放路径/public/data/nlp
数据集名称(定时更新,也可联系矩池云小助手):
| 名称 | 描述 |
|---|---|
| dbpedia_14 | 基于DBpedia2014的14个不重叠的分类数据集,包含40,000训练样本和5,000测试样本。源自维基百科的语义词条 |
| glue | 通用语言理解评估基准,面向9项任务的数据集,参考gluebenchmark |
| newsgroup | 用于文本分类、文本挖据和信息检索研究的国际标准数据集之一。数据集收集了大约20,000左右的新闻组文档,均匀分为20个不同主题的新闻组集合 |
| squad | 斯坦福问答数据集,一个阅读理解数据集 |
| super_glue | 更新版的Glue数据集 |
| wikitext | 英语词库数据是由Salesforce MetaMind 策划的包含1亿个词汇的大型语言建模语料库。这些词汇都是从维基百科一些经典文章中提取得到 |
| yahooAnswers | 数据集源于 Yahoo!Answers Comprehensive Questions and Answers 1.0 的 10 个主要分类数据,每个类别分别包含 140000 个训练样本和 5000 个测试样本 |
| yelp_review_full | 这个数据集是Yelp业务、评论和用户数据的一个子集。包含大量的评论、业务、用户、提示和签到数据 |
3.2 数据集使用方法
首先需要将自己需要使用的预训练模型zip文件解压到矩池云网盘或者机器中其他目录(存到网盘后下次可以直接使用),使用数据集时在代码抬头添加代码from datasets import load_from_disk,并将代码中加载数据集函数load_dataset更改为load_from_disk(数据集存放路径)即可。部分数据集需指定Subset。
以使用dbpedia_14数据集为例子:
解压,将数据集解压到网盘中(确保网盘空间足够)
unzip /public/data/nlp/dbpedia_14.zip -d /mnt/
代码中使用
如果环境中没有datasets包,可以先pip install datasets安装。
from datasets import load_from_disk
data = load_from_disk('/mnt/dbpedia_14')
# 注意 /mnt/dbpedia_14 是你解压后数据集文件所在路径
边栏推荐
- Five steps to successfully complete threat modeling
- SSD [target detection]
- Devsecops: ten things that should be done well
- matrial3d参数分析
- 运维安全,没那么简单
- Never ending database injection attack and defense
- 【100个 Unity踩坑小知识点】| Unity中的 碰撞盒检测 Physics.OverlapBox、OverlapCaps
- 国宝上新计划-四大博物馆独家数字珍藏强势来袭!
- 使用赞美提高绩效
- 有意思的鼠标指针交互探究
猜你喜欢

开源FTP 服务器 FileZilla Server

R & S oscilloscope software, introduction to upper computer software ns-scope of rod and Schwartz oscilloscope

基于QtQuick的QCustomPlot实现

学者魔改 Qt Creator 插件框架(附实例)

导航栏切换,留言板,文本框失去焦点
![[Harbin Institute of technology] information sharing for the first and second examinations of postgraduate entrance examination](/img/06/df5a64441814c9ecfa2f039318496e.jpg)
[Harbin Institute of technology] information sharing for the first and second examinations of postgraduate entrance examination
![SSD [target detection]](/img/f5/1a4a9868cddb24fb08db9fae4db290.png)
SSD [target detection]

Deep water area involvement

fix libpng warning: iCCP: Not recognizing known sRGB profile ......

阿宽食品:“方便食品第一股”争夺战继续
随机推荐
2022安全员-B证复训题库及模拟考试
贺志理:红树林湿地沉积物中微生物驱动的碳氮硫磷循环及其耦合机制
数据库主键一定要自增吗?有哪些场景不建议自增?
【100个 Unity踩坑小知识点】| Unity中的 碰撞盒检测 Physics.OverlapBox、OverlapCaps
XML entity injection vulnerability
qmlbook学习总结
fix libpng warning: iCCP: Not recognizing known sRGB profile ......
Hezhili: microbial driven carbon nitrogen sulfur phosphorus cycle in mangrove wetland sediments and its coupling mechanism
DevSecOps:初入江湖
Clear the switch configuration, configure the image port and Wireshark packet capturing (take Huawei s5720 as an example)
qt对sqlite数据库多线程的操作
One's deceased father grind politics English average cent furnace! What is your current level?
转赠券发放倒计时!星际口袋转赠规则抢先看
When gdpr knocks
重磅,MapStruct 1.5 发布,这次终于支持Map转为Bean了!
QT operation on SQLite database multithreading
ACM. HJ36 字符串加密 ●●
Introduction to the upper computer software ns-scope of Tektronix oscilloscope
导航栏切换,留言板,文本框失去焦点
R&S示波器软件,罗德与施瓦茨示波器上位机软件NS-Scope介绍
