当前位置:网站首页>HuggingFace
HuggingFace
2022-04-23 10:48:00 【qq1033930618】
List of articles
One 、 Official website
huggingface.co
Two 、 Model download
Installation in the environment transformers package
conda install -n conda Virtual environment name transformers
The model is automatically downloaded In quotation marks is the model name
from transformers import BertTokenizer, BertModel
model = BertModel.from_pretrained('bert-base-chinese', output_hidden_states = True,)
tokenizer = BertTokenizer.from_pretrained('bert-base-chinese')
Model auto download location
/home/ user name /.cache/huggingface/transformers
Manual Download
Search the model name at the top of the page
Click on Model card On the right side of the Files and Versions
The local path where the incoming model is saved
model = BertModel.from_pretrained('./model', output_hidden_states = True,)
tokenizer = BertTokenizer.from_pretrained('./model/vocab.txt')
Be careful ,BertModel.from_pretrained Enter the path of the folder
BertTokenizer.from_pretrained The input is vocab.txt, instead of tokenizer.json.
Speed up the download
model = BertModel.from_pretrained('bert-base-chinese', mirror='tuna')
3、 ... and 、 The Conduit pipeline
Use the model directly
from transformers import pipeline
classifier = pipeline("sentiment-analysis") # Emotional analysis model
classifier("We are very happy to show you the Transformers library.")
''' Returns a list of ( Contains a dictionary Dictionary key by label and score)'''
''' Multiple can use list input '''
results = classifier(["We are very happy to show you the Transformers library.", "We hope you don't hate it."])
''' Returns a list of multiple dictionaries '''
for result in results:
print(f"label: {result['label']}, with score: {round(result['score'], 4)}")
Load from dataset
pip install datasets
''' Specify classification and model ( speech recognition ) If only the classification is specified, the model will be randomly selected '''
speech_recognizer = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h", device=0)
files = dataset["file"]
speech_recognizer(files[:4])
Four 、 Mark tokenizer
''' Used to hold the model '''
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
''' Print '''
classifier("Nous sommes très heureux de vous présenter la bibliothèque Transformers.")
5、 ... and 、 Automatic class AutoClass
''' Automatically retrieve the architecture of the model in the name or path of the pre trained model relation AutoTokenizer'''
6、 ... and 、 Automatic vocabulary AutoTokenizer
Split text into multiple words To the extent that the text is understandable
from transformers import AutoTokenizer
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
encoding = tokenizer("We are very happy to show you the Transformers library.")
print(encoding)
{
'input_ids': [101, 11312, 10320, 12495, 19308, 10114, 11391, 10855, 10103, 100, 58263, 13299, 119, 102],
'token_type_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
版权声明
本文为[qq1033930618]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230618497078.html
边栏推荐
- Can Jerry's AES 256bit [chapter]
- How to quickly download vscode
- Understand the new economic model of platofarm and its ecological progress
- IDEA——》每次启动都会Indexing或 scanning files to index
- Simple thoughts on the design of a microblog database
- JVM - common parameters
- Charles function introduction and use tutorial
- 454. Sum of four numbers (hash table)
- What if Jerry's function to locate the corresponding address is not accurate sometimes? [chapter]
- Leetcode22:括号生成
猜你喜欢
A diary of dishes | 238 Product of arrays other than itself
使用zerotier让异地设备组局域网
Jinglianwen technology - professional data annotation company and intelligent data annotation platform
【leetcode】107.二叉树的层序遍历II
Download and installation steps of xshell + xftp
Idea - indexing or scanning files to index every time you start
SQL Server 递归查询上下级
Manjaro installation and configuration (vscode, wechat, beautification, input method)
SSH利用私钥无密钥连接服务器踩坑实录
SQL Server cursor circular table data
随机推荐
Ansible cloud computing automation
Chapter 120 SQL function round
Sim Api User Guide(4)
主流手机分辨率与尺寸
C language - custom type
What about Jerry's stack overflow? [chapter]
Full stack cross compilation x86 completion process experience sharing
【leetcode】107.二叉树的层序遍历II
206. Reverse linked list (linked list)
Solve the problem of installing VMware after uninstalling
349. Intersection of two arrays
一个微博数据库设计带来的简单思考
A diary of dishes | 238 Product of arrays other than itself
Learning notes 7-depth neural network optimization
Installing MySQL with CentOS / Linux
Leetcode22:括号生成
Notes on concurrent programming of vegetables (V) thread safety and lock solution
142、环形链表||
997、有序数组的平方(数组)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)