调用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)
运行输出:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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 双重循环例子