文本分类模型
# !/usr/bin/env python3 import argparse import asyncio import json import os import random import time from datetime import datetime from pathlib import Path import httpx from openai import AsyncOpenAI # 配置 # LLM_BASE_URL os.getenv(LLM_BASE_URL) # LLM_MODEL os.getenv(LLM_MODEL) LLM_API_KEY os.getenv(LLM_API_KEY) or empty LLM_TIMEOUT float(os.getenv(LLM_TIMEOUT, 30)) # 对象种类 CATEGORIES [徽章, 戒指, 动物, 人物, 其他] CATEGORIES_STR 、.join(CATEGORIES) SYSTEM_PROMPT f你是一个文本分类专家。根据给定的文生图提示词判断主要对象的种类。 可选种类{CATEGORIES_STR} 严格只输出一个词不要解释。 async def classify(text: str) - str: 分类提示词 if not text.strip(): return client AsyncOpenAI(api_keyLLM_API_KEY, base_urlLLM_BASE_URL, http_clienthttpx.AsyncClient(timeoutLLM_TIMEOUT), ) try: resp await client.chat.completions.create(modelLLM_MODEL, messages[{role: system, content: SYSTEM_PROMPT}, {role: user, content: text.strip()}, ], temperature0.1, max_tokens20, ) result resp.choices[0].message.content.strip() # 提取第一个词 for cat in CATEGORIES: if cat in result: return cat return result finally: await client.close() async def main(): parser argparse.ArgumentParser() parser.add_argument(--output, typePath, defaultNone) parser.add_argument(--seed, typeint, defaultNone) args parser.parse_args() test_prompts [ # 人物 A single 3D designer art toy figure, presented in a strict horizontal triptych layout with left side view, middle front view, and right rear view. Strictly limited to a palette of exactly 4 pure colors: 1. Pure white for the head, gloves, and boots; 2. Dark ultramarine blue for the torso, arms, and legs; 3. Crimson red for the flowing cape; 4. Silver-grey for the facial mask details and chest logo., # 徽章 A beautifully crafted enamel pin badge, featuring a detailed dragon design in gold and red colors, with subtle metallic sheen, professional product photography, white background, high resolution, studio lighting., # 戒指 A stunning platinum engagement ring with a 2-carat diamond center stone, surrounded by smaller pavé-set diamonds, intricate filigree details on the band, elegant jewelry photography, soft natural lighting, macro shot, 8K., # 动物 A majestic golden eagle soaring through the sky with wings fully extended, dramatic sunset background, sharp focus on feathers, hyper-realistic wildlife photography, National Geographic style, 8K, cinematic composition., # 其他 A futuristic skyscraper with a sleek glass facade, reflecting the surrounding cityscape, dramatic night lighting, long exposure photography, architectural marvel, modern minimalist design, high resolution, 8K., # 其他 A delicious gourmet burger on a wooden table, perfectly chargrilled beef patty, melted cheddar cheese, crispy bacon, fresh lettuce and tomato, steam rising, warm ambient lighting, food photography, shallow depth of field, 8K, mouth-watering., ] results [] # 逐个测试 for i, prompt in enumerate(test_prompts, 1): total_start time.time() predicted await classify(prompt) results.append({predicted: predicted}) print(f{i} {predicted} {time.time() - total_start:.2f}) if __name__ __main__: asyncio.run(main())

相关新闻

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚 1. 离线高分:先排除训练集与评测集重叠 评测结果异常升高时,应先检查训练集、验证集和测试集的来源、版本与文本重叠。可在公开或合成语料上使用 N-gram 或 MinHash 检测,…

2026/10/28 15:51:29 阅读更多 →
2025届必备的AI辅助论文平台横评

2025届必备的AI辅助论文平台横评

Ai论文网站排名(开题报告、文献综述、降aigc率、降重综合对比) TOP1. 千笔AI TOP2. aipasspaper TOP3. 清北论文 TOP4. 豆包 TOP5. kimi TOP6. deepseek 正变得越来越受众多学生青睐的, 能用来撰写学术文章的免费AI论文工具, 因人工智能迅速发展,…

2026/11/5 8:40:12 阅读更多 →
BiliTools:让B站视频学习效率提升3倍的智能工具箱

BiliTools:让B站视频学习效率提升3倍的智能工具箱

BiliTools:让B站视频学习效率提升3倍的智能工具箱 【免费下载链接】BiliTools 本项目已停止维护。 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools 在B站学习已经成为许多人的日常习惯,但面对数小时的视频课程,如何高…

2026/11/8 8:29:44 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/10 23:32:01 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/10 23:32:03 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/11 2:31:33 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/11 17:16:37 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/11 17:16:37 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/10 23:32:10 阅读更多 →

日新闻

周新闻

月新闻