调用huggingface_hub将内容向量化

环境:
OS:Windows 10
Python:3.10.11
pycharm:2023.2

 

前提条件:需要安装如下的包

 

pip install transformers --timeout=100
pip install sentence_transformers --timeout=100

 

注意numpy需要安装如下版本
pip install numpy==1.26.4

 

 

1.pycharm里面确定安装了huggingface_hub
如下:

 

2.修改constants.py文件
D:\python-3.10.11\Lib\site-packages\huggingface_hub\constants.py

##ENDPOINT = os.getenv("HF_ENDPOINT") or (_HF_DEFAULT_STAGING_ENDPOINT if _staging_mode else _HF_DEFAULT_ENDPOINT) ##注释掉该行
ENDPOINT ="https://hf-mirror.com" ##新增该行

 

3.运行例子
例子来自官网
https://hf-mirror.com/sentence-transformers/all-MiniLM-L6-v2

复制代码
#!/usr/bin/env python
#coding=utf-8

from sentence_transformers import SentenceTransformer

sentences = ["This is an example sentence", "Each sentence is converted"]

##model = SentenceTransformer(model_name_or_path='all-MiniLM-L6-v2', local_files_only=False)
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
embeddings = model.encode(sentences)
print(embeddings)
复制代码

 

运行输出:

 

posted @   slnngk  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2023-08-13 windows 10下编译mariadb
2021-08-13 [Warning] InnoDB: A long semaphore wait
2019-08-13 golang发送html邮件带附件
2019-08-13 双重循环例子
点击右上角即可分享
微信分享提示