当前位置:网站首页>使用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 是你解压后数据集文件所在路径
边栏推荐
- 2022 safety officer-b certificate retraining question bank and simulated examination
- 浅谈外包安全开发管控
- SSD【目标检测篇】
- qmlbook学习总结
- The first question of leetcode -- sum of two numbers
- 告别无尽盛夏
- From zero into the world of software development
- 转赠券发放倒计时!星际口袋转赠规则抢先看
- When gdpr knocks
- Illustrated with pictures and texts -- wechat applet to obtain the user's geographic location information and call Tencent map API to obtain the user's specific location
猜你喜欢

重磅,MapStruct 1.5 发布,这次终于支持Map转为Bean了!

XML entity injection vulnerability

第九章Cisco ASA应用NAT

Citus 11 for Postgres is completely open source and can be queried from any node (citus official blog)

有意思的鼠标指针交互探究

开源FTP 服务器 FileZilla Server

There are obvious signs of oversupply of chips, ASML is no longer a pastry, and investment institutions are shorting on a large scale

Introduction to common source oscilloscope software and RIGOL oscilloscope upper computer software ns-scope

In the graduation season, tell me about my feelings when I first entered the workplace as a student

Young people are reluctant to change their mobile phones, because they choose a more durable iPhone, and the parameter theory of domestic mobile phones is invalid
随机推荐
C# Cannot access child value on Newtonsoft. Json. Linq. JProperty
harmonyos培训一
游戏机之AR机械臂
OpenGL学习笔记之坐标变换学习
启牛学堂给的华泰证券账户是不是真的?开户安全吗
Implementation of qcustomplot based on qtquick
图文并茂--微信小程序,获取用户地理位置信息,并调用腾讯地图API来获取用户具体位置
服务器被入侵了怎么办
求你了,别在高并发场景中使用悲观锁了!
Citus 11 for Postgres is completely open source and can be queried from any node (citus official blog)
2022年高压电工判断题及答案
中国企业海外业务DDoS防护探索
Runaway player
Research on DDoS protection for overseas business of Chinese Enterprises
Broken knowledge
考研政英平均分出炉!你目前什么水平?
2022 safety officer-b certificate retraining question bank and simulated examination
Kotlin - Sequence 序列
巴比特 | 元宇宙每日必读:微信或首次以“涉数字藏品二级交易”为由封禁一公众号,平台新规也对此提出警告...
容器静态安全漏洞扫描工具Clair介绍
