hg transformers pipeline使用
什么是hg transformers pipeline?
在Hugging Face的transformers
库中,pipeline
是一个高级API,它提供了一种简便的方式来使用预训练模型进行各种NLP任务,比如情感分析、文本生成、翻译、问答等。通过pipeline
,你可以在几行代码内实现复杂的NLP任务。pipeline
会自动加载用于指定任务的默认模型和tokenizer,如果需要,用户也可以指定使用特定的模型和tokenizer
在创建pipeline
时,除了可以指定任务类型和模型外,还可以设置其他参数,比如使用的深度学习框架("pt"代表PyTorch,"tf"代表TensorFlow)、设备(CPU或GPU)、批量处理大小等 。pipeline
背后的实现包括初始化Tokenizer、Model,并进行数据预处理
以下是对pipelines
主要特点和功能的总结:
- 任务特定: Pipelines为多种NLP任务提供了特定的接口,如文本分类、命名实体识别、问答、文本生成、翻译、摘要和情感分析等。
- 模型自动加载: 用户无需关心背后的模型细节,pipelines会自动加载适合任务的预训练模型和tokenizer。
- 易于使用: Pipelines提供了简洁的API,用户只需几行代码即可加载模型并进行任务处理。
- 自动分词: Pipelines内部处理文本的分词,将文本转换为模型能理解的格式。
- 批处理: Pipelines支持批处理,可以同时处理多条文本数据。
- 动态调整: Pipelines可以根据输入数据的需要自动调整模型输入,如填充(padding)和截断(truncation)。
- 自定义模型和分词器: 用户可以指定自定义的模型和分词器,以适应特定的需求。
- 模型微调: 在使用pipelines进行任务之前,用户还可以对模型进行微调,以适应特定的数据集。
- 多语言支持: 许多pipelines支持多种语言,使得跨语言的NLP任务成为可能。
- 可扩展性: 用户可以根据自己的需求,使用pipelines作为构建块,构建更复杂的NLP流程。
- 性能优化: Pipelines针对常见用例进行了优化,以提供高性能的NLP任务处理。
- 错误处理: Pipelines提供了错误处理机制,以应对加载模型或处理文本时可能出现的问题。
通过使用pipelines,研究人员和开发者可以快速原型开发和部署NLP应用,而无需深入了解模型的内部工作原理。简而言之,pipelines是Hugging Face Transformers库中一个强大且灵活的工具,用于简化NLP任务的处理流程。
支持的任务分类
可用于音频、计算机视觉、自然语言处理和多模态任务
TASK_ALIASES = { "sentiment-analysis": "text-classification", "ner": "token-classification", "vqa": "visual-question-answering", "text-to-speech": "text-to-audio",
}
SUPPORTED_TASKS = { "audio-classification": { "impl": AudioClassificationPipeline, "tf": (), "pt": (AutoModelForAudioClassification,) if is_torch_available() else (), "default": {"model": {"pt": ("superb/wav2vec2-base-superb-ks", "372e048")}}, "type": "audio", }, "automatic-speech-recognition": { "impl": AutomaticSpeechRecognitionPipeline, "tf": (), "pt": (AutoModelForCTC, AutoModelForSpeechSeq2Seq) if is_torch_available() else (), "default": {"model": {"pt": ("facebook/wav2vec2-base-960h", "55bb623")}}, "type": "multimodal", }, "text-to-audio": { "impl": TextToAudioPipeline, "tf": (), "pt": (AutoModelForTextToWaveform, AutoModelForTextToSpectrogram) if is_torch_available() else (), "default": {"model": {"pt": ("suno/bark-small", "645cfba")}}, "type": "text", }, "feature-extraction": { "impl": FeatureExtractionPipeline, "tf": (TFAutoModel,) if is_tf_available() else (), "pt": (AutoModel,) if is_torch_available() else (), "default": { "model": { "pt": ("distilbert/distilbert-base-cased", "935ac13"), "tf": ("distilbert/distilbert-base-cased", "935ac13"), } }, "type": "multimodal", }, "text-classification": { "impl": TextClassificationPipeline, "tf": (TFAutoModelForSequenceClassification,) if is_tf_available() else (), "pt": (AutoModelForSequenceClassification,) if is_torch_available() else (), "default": { "model": { "pt": ("distilbert/distilbert-base-uncased-finetuned-sst-2-english", "af0f99b"), "tf": ("distilbert/distilbert-base-uncased-finetuned-sst-2-english", "af0f99b"), }, }, "type": "text", }, "token-classification": { "impl": TokenClassificationPipeline, "tf": (TFAutoModelForTokenClassification,) if is_tf_available() else (), "pt": (AutoModelForTokenClassification,) if is_torch_available() else (), "default": { "model": { "pt": ("dbmdz/bert-large-cased-finetuned-conll03-english", "f2482bf"), "tf": ("dbmdz/bert-large-cased-finetuned-conll03-english", "f2482bf"), }, }, "type": "text", }, "question-answering": { "impl": QuestionAnsweringPipeline, "tf": (TFAutoModelForQuestionAnswering,) if is_tf_available() else (), "pt": (AutoModelForQuestionAnswering,) if is_torch_available() else (), "default": { "model": { "pt": ("distilbert/distilbert-base-cased-distilled-squad", "626af31"), "tf": ("distilbert/distilbert-base-cased-distilled-squad", "626af31"), }, }, "type": "text", }, "table-question-answering": { "impl": TableQuestionAnsweringPipeline, "pt": (AutoModelForTableQuestionAnswering,) if is_torch_available() else (), "tf": (TFAutoModelForTableQuestionAnswering,) if is_tf_available() else (), "default": { "model": { "pt": ("google/tapas-base-finetuned-wtq", "69ceee2"), "tf": ("google/tapas-base-finetuned-wtq", "69ceee2"), }, }, "type": "text", }, "visual-question-answering": { "impl": VisualQuestionAnsweringPipeline, "pt": (AutoModelForVisualQuestionAnswering,) if is_torch_available() else (), "tf": (), "default": { "model": {"pt": ("dandelin/vilt-b32-finetuned-vqa", "4355f59")}, }, "type": "multimodal", }, "document-question-answering": { "impl": DocumentQuestionAnsweringPipeline, "pt": (AutoModelForDocumentQuestionAnswering,) if is_torch_available() else (), "tf": (), "default": { "model": {"pt": ("impira/layoutlm-document-qa", "52e01b3")}, }, "type": "multimodal", }, "fill-mask": { "impl": FillMaskPipeline, "tf": (TFAutoModelForMaskedLM,) if is_tf_available() else (), "pt": (AutoModelForMaskedLM,) if is_torch_available() else (), "default": { "model": { "pt": ("distilbert/distilroberta-base", "ec58a5b"), "tf": ("distilbert/distilroberta-base", "ec58a5b"), } }, "type": "text", }, "summarization": { "impl": SummarizationPipeline, "tf": (TFAutoModelForSeq2SeqLM,) if is_tf_available() else (), "pt": (AutoModelForSeq2SeqLM,) if is_torch_available() else (), "default": { "model": {"pt": ("sshleifer/distilbart-cnn-12-6", "a4f8f3e"), "tf": ("google-t5/t5-small", "d769bba")} }, "type": "text", }, # This task is a special case as it's parametrized by SRC, TGT languages. "translation": { "impl": TranslationPipeline, "tf": (TFAutoModelForSeq2SeqLM,) if is_tf_available() else (), "pt": (AutoModelForSeq2SeqLM,) if is_torch_available() else (), "default": { ("en", "fr"): {"model": {"pt": ("google-t5/t5-base", "686f1db"), "tf": ("google-t5/t5-base", "686f1db")}}, ("en", "de"): {"model": {"pt": ("google-t5/t5-base", "686f1db"), "tf": ("google-t5/t5-base", "686f1db")}}, ("en", "ro"): {"model": {"pt": ("google-t5/t5-base", "686f1db"), "tf": ("google-t5/t5-base", "686f1db")}}, }, "type": "text", }, "text2text-generation": { "impl": Text2TextGenerationPipeline, "tf": (TFAutoModelForSeq2SeqLM,) if is_tf_available() else (), "pt": (AutoModelForSeq2SeqLM,) if is_torch_available() else (), "default": {"model": {"pt": ("google-t5/t5-base", "686f1db"), "tf": ("google-t5/t5-base", "686f1db")}}, "type": "text", }, "text-generation": { "impl": TextGenerationPipeline, "tf": (TFAutoModelForCausalLM,) if is_tf_available() else (), "pt": (AutoModelForCausalLM,) if is_torch_available() else (), "default": {"model": {"pt": ("openai-community/gpt2", "6c0e608"), "tf": ("openai-community/gpt2", "6c0e608")}}, "type": "text", }, "zero-shot-classification": { "impl": ZeroShotClassificationPipeline, "tf": (TFAutoModelForSequenceClassification,) if is_tf_available() else (), "pt": (AutoModelForSequenceClassification,) if is_torch_available() else (), "default": { "model": { "pt": ("facebook/bart-large-mnli", "c626438"), "tf": ("FacebookAI/roberta-large-mnli", "130fb28"), }, "config": { "pt": ("facebook/bart-large-mnli", "c626438"), "tf": ("FacebookAI/roberta-large-mnli", "130fb28"), }, }, "type": "text", }, "zero-shot-image-classification": { "impl": ZeroShotImageClassificationPipeline, "tf": (TFAutoModelForZeroShotImageClassification,) if is_tf_available() else (), "pt": (AutoModelForZeroShotImageClassification,) if is_torch_available() else (), "default": { "model": { "pt": ("openai/clip-vit-base-patch32", "f4881ba"), "tf": ("openai/clip-vit-base-patch32", "f4881ba"), } }, "type": "multimodal", }, "zero-shot-audio-classification": { "impl": ZeroShotAudioClassificationPipeline, "tf": (), "pt": (AutoModel,) if is_torch_available() else (), "default": { "model": { "pt": ("laion/clap-htsat-fused", "973b6e5"), } }, "type": "multimodal", }, "conversational": { "impl": ConversationalPipeline, "tf": (TFAutoModelForSeq2SeqLM, TFAutoModelForCausalLM) if is_tf_available() else (), "pt": (AutoModelForSeq2SeqLM, AutoModelForCausalLM) if is_torch_available() else (), "default": { "model": {"pt": ("microsoft/DialoGPT-medium", "8bada3b"), "tf": ("microsoft/DialoGPT-medium", "8bada3b")} }, "type": "text", }, "image-classification": { "impl": ImageClassificationPipeline, "tf": (TFAutoModelForImageClassification,) if is_tf_available() else (), "pt": (AutoModelForImageClassification,) if is_torch_available() else (), "default": { "model": { "pt": ("google/vit-base-patch16-224", "5dca96d"), "tf": ("google/vit-base-patch16-224", "5dca96d"), } }, "type": "image", }, "image-feature-extraction": { "impl": ImageFeatureExtractionPipeline, "tf": (TFAutoModel,) if is_tf_available() else (), "pt": (AutoModel,) if is_torch_available() else (), "default": { "model": { "pt": ("google/vit-base-patch16-224", "3f49326"), "tf": ("google/vit-base-patch16-224", "3f49326"), } }, "type": "image", }, "image-segmentation": { "impl": ImageSegmentationPipeline, "tf": (), "pt": (AutoModelForImageSegmentation, AutoModelForSemanticSegmentation) if is_torch_available() else (), "default": {"model": {"pt": ("facebook/detr-resnet-50-panoptic", "fc15262")}}, "type": "multimodal", }, "image-to-text": { "impl": ImageToTextPipeline, "tf": (TFAutoModelForVision2Seq,) if is_tf_available() else (), "pt": (AutoModelForVision2Seq,) if is_torch_available() else (), "default": { "model": { "pt": ("ydshieh/vit-gpt2-coco-en", "65636df"), "tf": ("ydshieh/vit-gpt2-coco-en", "65636df"), } }, "type": "multimodal", }, "object-detection": { "impl": ObjectDetectionPipeline, "tf": (), "pt": (AutoModelForObjectDetection,) if is_torch_available() else (), "default": {"model": {"pt": ("facebook/detr-resnet-50", "2729413")}}, "type": "multimodal", }, "zero-shot-object-detection": { "impl": ZeroShotObjectDetectionPipeline, "tf": (), "pt": (AutoModelForZeroShotObjectDetection,) if is_torch_available() else (), "default": {"model": {"pt": ("google/owlvit-base-patch32", "17740e1")}}, "type": "multimodal", }, "depth-estimation": { "impl": DepthEstimationPipeline, "tf": (), "pt": (AutoModelForDepthEstimation,) if is_torch_available() else (), "default": {"model": {"pt": ("Intel/dpt-large", "e93beec")}}, "type": "image", }, "video-classification": { "impl": VideoClassificationPipeline, "tf": (), "pt": (AutoModelForVideoClassification,) if is_torch_available() else (), "default": {"model": {"pt": ("MCG-NJU/videomae-base-finetuned-kinetics", "4800870")}}, "type": "video", }, "mask-generation": { "impl": MaskGenerationPipeline, "tf": (), "pt": (AutoModelForMaskGeneration,) if is_torch_available() else (), "default": {"model": {"pt": ("facebook/sam-vit-huge", "997b15")}}, "type": "multimodal", }, "image-to-image": { "impl": ImageToImagePipeline, "tf": (), "pt": (AutoModelForImageToImage,) if is_torch_available() else (), "default": {"model": {"pt": ("caidas/swin2SR-classical-sr-x2-64", "4aaedcb")}}, "type": "image", },
}
使用示例
简单使用示例
from transformers import pipeline
from transformers.pipelines import get_supported_tasks
import json nlp = pipeline("sentiment-analysis")
# 单次调用
result = nlp("I hate you")[0]
print(f"label: {result['label']}, score: {round(result['score'], 4)}")
# label: NEGATIVE, with score: 0.9991
result = nlp("I love you")[0]
print(f"label: {result['label']}, score: {round(result['score'], 4)}")
# label: POSITIVE, with score # 多次调用
result = nlp(["This restaurant is awesome", "This restaurant is awful"])
print(json.dumps(result)) print(json.dumps(get_supported_tasks()))
执行的输出日志如下:
- 因为未指定model,默认根据任务分类名称从hg下载对应的模型,sentiment-analysis任务对应的默认模型是:models–distilbert–distilbert-base-uncased-finetuned-sst-2-english,默认是af0f99b
- 下载的model保存的默认目录是:C:\Users\用户名.cache\huggingface\hub\
- 不建议在生产环境中不指定model及版本
python.exe Classification.py
No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
D:\soft\anaconda3\envs\llm-demo\lib\site-packages\huggingface_hub\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.warnings.warn(
D:\soft\anaconda3\envs\llm-demo\lib\site-packages\huggingface_hub\file_download.py:157: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\Users\wang\.cache\huggingface\hub\models--distilbert--distilbert-base-uncased-finetuned-sst-2-english. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.
To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-developmentwarnings.warn(message)
label: NEGATIVE, score: 0.9991
label: POSITIVE, score: 0.9999[{"label": "POSITIVE", "score": 0.9998743534088135}, {"label": "NEGATIVE", "score": 0.9996669292449951}]["audio-classification", "automatic-speech-recognition", "conversational", "depth-estimation", "document-question-answering", "feature-extraction", "fill-mask", "image-classification", "image-feature-extraction", "image-segmentation", "image-to-image", "image-to-text", "mask-generation", "ner", "object-detection", "question-answering", "sentiment-analysis", "summarization", "table-question-answering", "text-classification", "text-generation", "text-to-audio", "text-to-speech", "text2text-generation", "token-classification", "translation", "video-classification", "visual-question-answering", "vqa", "zero-shot-audio-classification", "zero-shot-classification", "zero-shot-image-classification", "zero-shot-object-detection"]
Pipeline batching
from transformers import pipeline
from transformers.pipelines.pt_utils import KeyDataset
import datasets dataset = datasets.load_dataset("imdb", name="plain_text", split="unsupervised") pipe = pipeline(task="sentiment-analysis") for out in pipe(KeyDataset(dataset, "text"), batch_size=8, truncation="only_first"): print(out)
自定义数据集
from transformers import pipeline
from torch.utils.data import Dataset
from tqdm.auto import tqdmpipe = pipeline("text-classification", device=0)class MyDataset(Dataset):def __len__(self):return 5000def __getitem__(self, i):return "This is a test"dataset = MyDataset()for batch_size in [1, 8, 64, 256]:print("-" * 30)print(f"Streaming batch_size={batch_size}")for out in tqdm(pipe(dataset, batch_size=batch_size), total=len(dataset)):pass
文本summary
# use bart in pytorch
summarizer = pipeline("summarization")
summarizer("An apple a day, keeps the doctor away", min_length=5, max_length=20)# use t5 in tf
summarizer = pipeline("summarization", model="google-t5/t5-base", tokenizer="google-t5/t5-base", framework="tf")
summarizer("An apple a day, keeps the doctor away", min_length=5, max_length=20)
学习资料
- https://huggingface.co/docs/transformers/main_classes/pipelines
- https://huggingface.co/docs/transformers/task_summary#text-classification
相关文章:

hg transformers pipeline使用
什么是hg transformers pipeline? 在Hugging Face的transformers库中,pipeline是一个高级API,它提供了一种简便的方式来使用预训练模型进行各种NLP任务,比如情感分析、文本生成、翻译、问答等。通过pipeline,你可以在几行代码内…...

高性能内存对象缓存
Memcached概述 一套开源的高性能分布式内存对象缓存系统 所有的数据都存储在内存中 支持任意存储类型的数据 提高网站的访问速度 数据存储方式与数据过期方式 数据存储方式:Slab Allocation 按组分配内存,每次先分配一个Slab,相当于一个大小为1M的页&…...

文件上传-CMS文件上传分析
黑盒思路: 上传点抓包测试 个人用户中心是否存在文件上传功能后台管理系统是否存在文件上传功能字典目录扫描探针文件(eg:upload.php)构造地址字典目录扫描探针编辑器目录构造地址(编辑器目录一般是默认的)…...

云原生日志Loki
1. Loki简介 1.1 Loki介绍 Loki是 Grafana Labs 团队最新的开源项目,是一个水平可扩展,高可用性,多租户的日志聚合系统。它的设计非常经济高效且易于操作,因为它不会为日志内容编制索引,而是为每个日志流编制一组标签…...

初阶数据结构之直接选择排序和快速排序
直接选择排序 1.在元素集合 array[i]–array[n-1] 中选择关键码最⼤(⼩)的数据元素 2.若它不是这组元素中的最后⼀个(第⼀个)元素,则将它与这组元素中的最后⼀个(第⼀个)元素 交换 3.在剩余的 array[i]–array[n-2](array[i1]–…...

Java语言程序设计——篇十三(4)
🌿🌿🌿跟随博主脚步,从这里开始→博主主页🌿🌿🌿 欢迎大家:这里是我的学习笔记、总结知识的地方,喜欢的话请三连,有问题可以私信🌳🌳&…...

低代码: 组件库测试之渲染和元素获取,触发事件,更新表单,验证事件以及异步请求
组件库测试步骤 渲染组件(怎样将一个组件渲染到测试用例里面) mount 和 shallowMount传递属性元素是否成功的显示 查找元素的不同写法get, getAllfind, findAllfindComponent 和 getComponent触发事件(是click也好,是input也好,让它触发对应的事件) trigger 方法观察测试界面…...

银河麒麟服务器操作系统Kylin-Server-V10-SP3-2403-Release-20240426-x86_64安装步骤
银河麒麟服务器操作系统 Kylin-Server-V10-SP3-2403-Release-20240426-x86_64安装步骤 一、准备工作1. 下载ISO镜像2. 制作安装介质3. 设置BIOS 二、安装过程1. 启动系统2. 选择安装语言3. 选择安装配置4. 配置root密码与创建用户5. 开始安装6. 重启系统7. 同意许可协议 三、系…...

2024年电赛H题全开源
当题目出来的的那一刻,看到了M0芯片,我们实验室只有一块板子,并且我没有接触过M0,电赛只准备了TI的MSP430f5529。但是我并没有放弃,决然的选择了H题。基本上将四问全做出来,可是测试由于使用了感为科技的寻…...

Docker:宿主机可以ping通外网,docker容器内无法ping通外网之解决方法
问题描述 1、宿主机可以ping外网,docker容器内无法ping外网 ping www.baidu.com 提示:unknown host baidu.com 2、宿主机可以wget下载,docker容器内无法wget下载 wget www.baidu.com 提示:unknown host baidu.com 解决方法 1、…...

bootchart抓Android系统启动各阶段性能数据
最近在做Android系统启动优化,首要任务是找到启动过程中各阶段耗时点,进而有针对性地进行优化。主要用bootchart抓开机数据,本文主要记录下工具的使用方法。 1.抓开机数据 adb root adb shell ‘touch /data/bootchart/enabled’ adb rebo…...

使用 Node.js 和 Express 框架通过网页访问GPIO和嵌入式 Linux 系统中使用 GSM/3G/4G 模块
点击上方"蓝字"关注我们 01、前言 想要快速开发嵌入式 Linux 网络应用,控制硬件 GPIO,从而使得用户能够远程控制和监控系统。 主要目的是向读者展示开发使用文件系统控制 GPIO 的 Node 代码、创建用户有好的界面、以及运行基于 Express 框架使用 AJAX 通客户端进…...

IT 行业的就业情况
当前,IT 行业的就业情况呈现出以下特点: 1. 需求持续增长:随着数字化转型的加速,各个行业对信息技术的依赖程度不断提高,推动了对 IT 人才的持续需求。特别是在云计算、大数据、人工智能、物联网等新兴领域ÿ…...

如何快速获取麒麟操作系统版本信息
如何快速获取麒麟操作系统版本信息 一、桌面版系统1. 使用 /etc/kylin-build 文件2. 使用 /etc/.kyinfo 文件 二、服务器版系统1. 使用 /etc/.productinfo 文件2. 使用 nkvers 命令3. 使用 /etc/kylin-release 文件 三、总结 💖The Begin💖点点关注&…...

git提交规范检查husky
一、Eslint 尤雨溪推荐的 prettierrc 配置,句尾不带分号 单引号。 尤雨溪推荐配置:vue-next/.prettierrc lint lint 是最著名的 C 语言工具之一,是由贝尔实验室 SteveJohnson 于 1979 在 PCC(PortableC Compiler) 基础上开发的静态代码分…...

LeetCode 919. 完全二叉树插入器
完全二叉树是每一层(除最后一层外)都是完全填充(即,节点数达到最大)的,并且所有的节点都尽可能地集中在左侧。 设计一个用完全二叉树初始化的数据结构 CBTInserter,它支持以下几种操作…...

C++密码管理器
先问一句 最近有几个关注我的原力等级为0或-1,文章全是转载,转载时间基本都在2021年,而且关注了很多人,这些是僵尸粉吗? 文末有投票,麻烦参与一下谢谢 实现功能列表 暂时还没做加密功能 打算用openssl/a…...

算法【Java】 —— 滑动窗口
滑动窗口 在上一篇文章中,我们了解到了双指针算法,在双指针算法中我们知道了前后指针法,这篇文章就要提到前后指针法的一个经典的使用 —— 滑动窗口,在前后指针法中,我们知道一个指针在前,一个指针在后&a…...

Spring Aware接口执行时机
一. 介绍 Spring Aware 接口的执行时机有两处,都在 getBean() 中的 initializeBean() 中; 下面我们分析这两处时机; // ----------------------- AbstractAutowireCapableBeanFactory --------------------- protected Object initializeB…...

android FD_SET_chk问题定位
android FD_SET_chk问题定位 一、FD报错二、问题定位2.1 APM定位2.2 adb定位2.3. 代码获取FD数 三、FD优化 一、FD报错 App在运行中记录报错如下,FD_SET,这个问题大概是文件描述符(File Descriptor,简称FD)超过了最大…...

Chapter 39 Python多线程编程
欢迎大家订阅【Python从入门到精通】专栏,一起探索Python的无限可能! 文章目录 前言一、并行执行二、threading模块 前言 现代操作系统如 macOS、UNIX、Linux 和 Windows 等,均支持多任务处理。本篇文章详细讲解了并行执行的概念以及如何在 …...

STM32(二):GPIO
GPIO(General Purpose Input Output)通用输入输出口 1.可配置为8种输入输出模式,引脚电平:0V~3.3V,部分引脚可容忍5V,输出模式下可控制端口输出高低电平,用以驱动LED、控制蜂鸣器、模拟通信协议输出时序等,输入模式下…...

一文入门mysql 数据库
一、对数据库的操作 1.展示所有的数据库 show databases; 2.创建数据库 create database 数据库名 charset utf8; 3.删除数据库 drop database 数据库名; 4.查看当前使用的数据库 select database(); 5.使用数据库 use 数据库名; 二、对数据表的操作 1.展示所有表…...

通义千问( 四 ) Function Call 函数调用
4.2.function call 函数调用 大模型在面对实时性问题、私域知识型问题或数学计算等问题时可能效果不佳。 您可以使用function call功能,通过调用外部工具来提升模型的输出效果。您可以在调用大模型时,通过tools参数传入工具的名称、描述、入参等信息。…...

设置idea中放缩字体大小
由于idea没默认支持ctrl滚轴对字体调节大小,下面一起设置一下吧! 点击 文件 -> 设置 按键映射 -> 编辑器操作 -> 搜索栏输入f 点击减小字体大小 -> 选择增加鼠标快捷键 按着ctrl键,鼠标向下滚动后,点击确定即可 然后…...

frameworks 之getEvent指令
frameworks 之getEvent指令 指令解析源码追溯源码解析1.解析参数2.初始化ufds数组3.添加到poll 并做对应处理 通过 getEvent 可以识别按键基本命令和里面的关键信息 涉及到的类如下 system/core/toolbox/toolbox.csystem/core/toolbox/tools.hsystem/core/toolbox/getevent.c …...

tensorboard显示一片空白解决方案
OK艾瑞巴蒂 不知道看这个视频几个小土堆过来的,今天已经发了一篇博文探讨快速下载tensorboard了 下面用的时候叒出现问题了 from torch.utils.tensorboard import SummaryWriter writer SummaryWriter("logs")# writer.add_image() # Yx for i in range…...

C#编程中,如何实现一个高效的数据排序算法?
在C#编程中,可以使用内置的排序方法来实现高效的数据排序。最常用的方法是使用Array.Sort()和List<T>.Sort()。这些方法内部使用了快速排序算法(Quick Sort),它是一种非常高效的排序算法,平均时间复杂度为O(n lo…...

LookupError: Resource averaged_perceptron_tagger not found.解决方案
大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作的方式对所学的…...

Leetcode JAVA刷刷站(39)组合总和
一、题目概述 二、思路方向 为了解决这个问题,我们可以使用回溯算法来找到所有可能的组合,使得组合中的数字之和等于目标数 target。因为数组中的元素可以无限制地重复选择,所以在回溯过程中,我们不需要跳过已经选择的元素&#x…...