当前位置: 首页 > ds >正文

【评测】Qwen3-Embedding模型初体验

每一篇文章前后都增加返回目录
回到目录

【评测】Qwen3-Embedding模型初体验

模型的介绍页面
本机配置:八代i5-8265U,16G内存,无GPU核显运行,win10操作系统
ollama可以通过下面命令拉取模型:
ollama pull modelscope.cn/Qwen/Qwen3-Embedding-8B-GGUF
下面直接使用介绍页面的sample代码体验一下模型的威力。

1. modelscope下载模型

$ modelscope download --model Qwen/Qwen3-Embedding-0.6B
$ modelscope download --model Qwen/Qwen3-Embedding-8B
0.6B模型 1.12GB 8B模型 14.1GB

2. 修改sample代码从本地加载模型

默认代码运行报错:
OSError: We couldn’t connect to ‘https://huggingface.co’ to load the files, and couldn’t find them in the cached files.

# test_qwen3-embedding.py# Requires transformers>=4.51.0
# Requires sentence-transformers>=2.7.0from sentence_transformers import SentenceTransformer# Load the model
#model = SentenceTransformer("Qwen/Qwen3-Embedding-8B")  改为下面代码本地加载模型
model = SentenceTransformer("C:\\Users\\Administrator\\.cache\\modelscope\\hub\models\\Qwen\\Qwen3-Embedding-8B")# We recommend enabling flash_attention_2 for better acceleration and memory saving,
# together with setting `padding_side` to "left":
# model = SentenceTransformer(
#     "Qwen/Qwen3-Embedding-8B",
#     model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
#     tokenizer_kwargs={"padding_side": "left"},
# )# The queries and documents to embed
queries = ["What is the capital of China?","Explain gravity",
]
documents = ["The capital of China is Beijing.","Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
]# Encode the queries and documents. Note that queries benefit from using a prompt
# Here we use the prompt called "query" stored under `model.prompts`, but you can
# also pass your own prompt via the `prompt` argument
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)# Compute the (cosine) similarity between the query and document embeddings
similarity = model.similarity(query_embeddings, document_embeddings)
print(similarity)
# tensor([[0.7493, 0.0751],
#         [0.0880, 0.6318]])

可能是机器配置太低问题,无法正常执行出结果
D:\workspace\test_qwen3-embedding.py:8: SyntaxWarning: invalid escape sequence ‘\m’
model = SentenceTransformer(“C:\Users\Administrator\.cache\modelscope\hub\models\Qwen\Qwen3-Embedding-8B”)
Loading checkpoint shards: 25%|██████████████▎ | 1/4 [00:14<00:42, 14.24s/it]

3. 修改sample代码为0.6B模型

# test_qwen3-embedding.py
。。。
# Load the model
#model = SentenceTransformer("Qwen/Qwen3-Embedding-8B")  改为下面代码本地加载模型
model = SentenceTransformer("C:\\Users\\Administrator\\.cache\\modelscope\\hub\models\\Qwen\\Qwen3-Embedding-8B")
。。。

(workspace) PS D:\workspace> uv run .\test_qwen3-embedding.py
D:\workspace\test_qwen3-embedding.py:8: SyntaxWarning: invalid escape sequence ‘\m’
model = SentenceTransformer(“C:\Users\Administrator\.cache\modelscope\hub\models\Qwen\Qwen3-Embedding-0.6B”)
tensor([[0.7646, 0.1414],
[0.1355, 0.6000]])

运行成功,几秒钟出结果,CPU呼呼的转,最终效果可以接受吗?

每一篇文章前后都增加返回目录
回到目录

http://www.xdnf.cn/news/13065.html

相关文章:

  • frida Hook入门
  • [FreeRTOS]1.FreeRTOS基础知识
  • Java处理字符数组转换为开始日期和结束日期
  • 【学习笔记】深入理解Java虚拟机学习笔记——第3章 垃圾收集器与内存分配策略
  • LLMs之MCP:《Evaluation Report on MCP Servers》翻译与解读
  • 『uniapp』自定义隐私政策弹窗 调整颜色和多语言国际化支持超链接 演示本地插件的使用,和一般性的插件自定义(保姆级图文)
  • CppCon 2015 学习:Live Lock-Free or Deadlock
  • AI架构师修炼之道
  • Linux系统编程中的_GNU_SOURCE宏
  • Promise 基础:异步编程的救星
  • 使用idea开发工具创建javaweb项目工程
  • CQF预备知识:Python相关库 -- 傅里叶变换 scipy.fft
  • 第十八章 归档与备份
  • python打卡第48天
  • linux库(AI回答)
  • SpringBoot的5种日志输出规范策略
  • 深入理解 x86 汇编中的符号扩展指令:从 CBW 到 CDQ 的全解析
  • 《光子技术成像技术》第三章 预习2025.6.8
  • 代码审计 BlueCms SQL注入
  • Linux 文件系统底层原理笔记:磁盘结构、ext2 文件系统与软硬链接解析
  • 基于Python学习《Head First设计模式》第九章 迭代器和组合模式
  • Spring Cloud 微服务架构实战指南 -- SpringCLoud概述
  • [深度学习]搭建开发平台及Tensor基础
  • 第23讲、Odoo18 二开常见陷阱
  • SQL导出Excel支持正则脱敏
  • AtCoder AT_abc409_c [ABC409C] Equilateral Triangle
  • Agent短期记忆的几种持久化存储方式
  • 时间序列预测的机器学习方法:从基础到实战
  • HTML前端开发:JavaScript 获取元素方法详解
  • 5. TypeScript 类型缩小