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

transformers 框架使用详解,bert-base-chinese

以 bert-base-chinese 模型为例,模型目录 model_name = "C:/Users/Administrator.DESKTOP-TPJL4TC/.cache/modelscope/hub/tiansz/bert-base-chinese"

bert-base-chinese 模型大小只有400多兆,参数的量级在百万级别,与现在动辄几十个G,几十亿几百亿的参数量级不在一个层次,所以 bert 的主要功能是理解语义,它的双向编码其实就是transformer论文中的自注意力的实现。既然能够理解语义,它就能实现一些延伸的能力。

1、两个句子相似度的比较。

2、实现简单的QA,即给它一段话作为context,然后根据这段话提问,它能定位到你这个问题的答案在context中的位置,然后将答案揪出来,当然,它不是generate模型,它的参数量也做不到generate,它只是简单的截取一句话作为最符合的答案。

3、命名实体识别NER

4、在NLP领域,你可以定义很多下游任务,当然要自己实现输出层的逻辑。

transformers的三大组件configuration, tokenizer和model都可以通过一致的from_pertrained()方法来实例化。

Transformers提供了三个主要的组件。

  • Configuration配置类。存储模型和分词器的参数,诸如词表大小,隐层维数,dropout rate等。配置类对深度学习框架是透明的。
  • Tokenizer分词器类。每个模型都有对应的分词器,存储token到index的映射,负责每个模型特定的序列编码解码流程,比如BPE(Byte Pair Encoding),SentencePiece等等。也可以方便地添加特殊token或者调整词表大小,如CLS、SEP等等。
  • Model模型类。提供一个基类,实现模型的计算图和编码过程,实现前向传播过程,通过一系列self-attention层直到最后一个隐藏状态层。在最后一层基础上,根据不同的应用会再做些封装,比如XXXForSequenceClassification,XXXForMaskedLM这些派生类。

Transformers的作者们还为以上组件提供了一系列Auto Classes,能够从一个短的别名(如bert-base-cased)里自动推测出来应该实例化哪种配置类、分词器类和模型类。

Transformers提供两大类的模型架构,一类用于语言生成NLG任务,比如GPT、GPT-2、Transformer-XL、XLNet和XLM,另一类主要用于语言理解任务,如Bert、DistilBert、RoBERTa、XLM.

tokenizer.encode() 方法

经过层层继承,最终的实现是在文件transformers\tokenization_utils_base.py中的 class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin):

def encode(self,text: Union[TextInput, PreTokenizedInput, EncodedInput],text_pair: Optional[Union[TextInput, PreTokenizedInput, EncodedInput]] = None,add_special_tokens: bool = True,padding: Union[bool, str, PaddingStrategy] = False,truncation: Union[bool, str, TruncationStrategy] = None,max_length: Optional[int] = None,stride: int = 0,padding_side: Optional[bool] = None,return_tensors: Optional[Union[str, TensorType]] = None,**kwargs,) -> List[int]:"""Converts a string to a sequence of ids (integer), using the tokenizer and vocabulary.Same as doing `self.convert_tokens_to_ids(self.tokenize(text))`.Args:text (`str`, `List[str]` or `List[int]`):The first sequence to be encoded. This can be a string, a list of strings (tokenized string using the`tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`method).text_pair (`str`, `List[str]` or `List[int]`, *optional*):Optional second sequence to be encoded. This can be a string, a list of strings (tokenized string usingthe `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`method)."""encoded_inputs = self.encode_plus(text,text_pair=text_pair,add_special_tokens=add_special_tokens,padding=padding,truncation=truncation,max_length=max_length,stride=stride,padding_side=padding_side,return_tensors=return_tensors,**kwargs,)return encoded_inputs["input_ids"]

model.eval() 的作用:模型在默认状态下是激活了 Dropout 模块,你此时给他输入数据会导致模型参数发生变化,所以需要调用eval()方法将模型设置为评估(evaluation)模式,deactivate DropOut modules。

python中的 __call__方法

它的作用为:当你把对象当做函数来调用时,例如 objectA(xxx),就会被重定向到__call__方法。

在类PreTrainedTokenizerBase

def __call__(self,text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,text_pair: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,text_target: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,text_pair_target: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,add_special_tokens: bool = True,padding: Union[bool, str, PaddingStrategy] = False,truncation: Union[bool, str, TruncationStrategy] = None,max_length: Optional[int] = None,stride: int = 0,is_split_into_words: bool = False,pad_to_multiple_of: Optional[int] = None,padding_side: Optional[bool] = None,return_tensors: Optional[Union[str, TensorType]] = None,return_token_type_ids: Optional[bool] = None,return_attention_mask: Optional[bool] = None,return_overflowing_tokens: bool = False,return_special_tokens_mask: bool = False,return_offsets_mapping: bool = False,return_length: bool = False,verbose: bool = True,**kwargs,) -> BatchEncoding:"""Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of sequences.Args:text (`str`, `List[str]`, `List[List[str]]`, *optional*):The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set`is_split_into_words=True` (to lift the ambiguity with a batch of sequences).text_pair (`str`, `List[str]`, `List[List[str]]`, *optional*):The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set`is_split_into_words=True` (to lift the ambiguity with a batch of sequences).text_target (`str`, `List[str]`, `List[List[str]]`, *optional*):The sequence or batch of sequences to be encoded as target texts. Each sequence can be a string or alist of strings (pretokenized string). If the sequences are provided as list of strings (pretokenized),you must set `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).text_pair_target (`str`, `List[str]`, `List[List[str]]`, *optional*):The sequence or batch of sequences to be encoded as target texts. Each sequence can be a string or alist of strings (pretokenized string). If the sequences are provided as list of strings (pretokenized),you must set `is_split_into_words=True` (to lift the ambiguity with a batch of sequences)."""......

此时,你就看到有这样的调用

tokenizer = BertTokenizer.from_pretrained(model_name)
model = BertForQuestionAnswering.from_pretrained(model_name)inputs = tokenizer(question, context, return_tensors="pt")
outputs = model(**inputs)

model() 实际上调用的就是 model.forward() 。

而 tokenizer() 并不是 tokenizer.decode() ,从返回值类型就能看出来。从代码上看,tokenizer() 做了一些判断,返回值为 BatchEncoding;而 tokenizer.decode() 返回值为 BatchEncoding[‘input_ids’],所以也可以

input_ids = tokenizer.encode(question, context, return_tensors="pt")
outputs = model(input_ids)
model = xxx.from_pretrained(model_name) 的问题

同一个模型,可以有不同的下游任务,网络模型包括输入层,中间隐藏层,输出层三部分。我们所说的下游任务就是指输出层,我们拿到隐藏层的最后一层的计算结果之后,就可以在输出层上做些文章以实现不同的功能,所以在实例化模型的时候会有多种方式,AutoModelForxxxx,或者 BertForxxxx,所以 model() 的输出结果就不一样,参数个数也可能不一样,这个要去看它的 forward() 方法。

多去看看代码,基本上都有说明。我们以BertForQuestionAnswering为例

from transformers import BertTokenizer, BertForQuestionAnswering
model = BertForQuestionAnswering.from_pretrained(model_name)
......
outputs = model(**inputs)

类的定义如下

@add_start_docstrings("""Bert Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linearlayers on top of the hidden-states output to compute `span start logits` and `span end logits`).""",BERT_START_DOCSTRING,
)
class BertForQuestionAnswering(BertPreTrainedModel):def __init__(self, config):......def forward(self,input_ids: Optional[torch.Tensor] = None,attention_mask: Optional[torch.Tensor] = None,token_type_ids: Optional[torch.Tensor] = None,position_ids: Optional[torch.Tensor] = None,head_mask: Optional[torch.Tensor] = None,inputs_embeds: Optional[torch.Tensor] = None,start_positions: Optional[torch.Tensor] = None,end_positions: Optional[torch.Tensor] = None,output_attentions: Optional[bool] = None,output_hidden_states: Optional[bool] = None,return_dict: Optional[bool] = None,) -> Union[Tuple[torch.Tensor], QuestionAnsweringModelOutput]:

从说明就知道此类提供question-answering任务,它的返回值是 Tuple[torch.Tensor] 或者 QuestionAnsweringModelOutput,通过传入的参数 return_dict 来决定返回值类型,默认就是返回 QuestionAnsweringModelOutput,它是一个dataclass,可以访问它的属性。

再比如

from transformers import BertTokenizer, AutoModel
model = AutoModel.from_pretrained(model_name)
print(type(model)) # <class 'transformers.models.bert.modeling_bert.BertModel'>

类的定义如下

@add_start_docstrings("The bare Bert Model transformer outputting raw hidden-states without any specific head on top.",BERT_START_DOCSTRING,
)
class BertModel(BertPreTrainedModel):"""The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer ofcross-attention is added between the self-attention layers, following the architecture described in [Attention isall you need](https://arxiv.org/abs/1706.03762) by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit,Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.To behave as an decoder the model needs to be initialized with the `is_decoder` argument of the configuration setto `True`. To be used in a Seq2Seq model, the model needs to initialized with both `is_decoder` argument and`add_cross_attention` set to `True`; an `encoder_hidden_states` is then expected as an input to the forward pass."""_no_split_modules = ["BertEmbeddings", "BertLayer"]def __init__(self, config, add_pooling_layer=True):......def forward(self,input_ids: Optional[torch.Tensor] = None,attention_mask: Optional[torch.Tensor] = None,token_type_ids: Optional[torch.Tensor] = None,position_ids: Optional[torch.Tensor] = None,head_mask: Optional[torch.Tensor] = None,inputs_embeds: Optional[torch.Tensor] = None,encoder_hidden_states: Optional[torch.Tensor] = None,encoder_attention_mask: Optional[torch.Tensor] = None,past_key_values: Optional[List[torch.FloatTensor]] = None,use_cache: Optional[bool] = None,output_attentions: Optional[bool] = None,output_hidden_states: Optional[bool] = None,return_dict: Optional[bool] = None,) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPoolingAndCrossAttentions]:

从说明就知道此类只能作为encoder和decoder用,其返回值为 Tuple[torch.Tensor] 或者 BaseModelOutputWithPoolingAndCrossAttentions

@dataclass 的说明
@dataclass
class QuestionAnsweringModelOutput(ModelOutput):"""Base class for outputs of question answering models.Args:loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.start_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):Span-start scores (before SoftMax).end_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):Span-end scores (before SoftMax).hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,sequence_length)`.Attentions weights after the attention softmax, used to compute the weighted average in the self-attentionheads."""loss: Optional[torch.FloatTensor] = Nonestart_logits: torch.FloatTensor = Noneend_logits: torch.FloatTensor = Nonehidden_states: Optional[Tuple[torch.FloatTensor, ...]] = Noneattentions: Optional[Tuple[torch.FloatTensor, ...]] = None

此装饰器的作用相当于定义了一系列的类的属性

def __init__(self, loss: Optional[torch.FloatTensor] = Nonestart_logits: torch.FloatTensor = Noneend_logits: torch.FloatTensor = Nonehidden_states: Optional[Tuple[torch.FloatTensor, ...]] = Noneattentions: Optional[Tuple[torch.FloatTensor, ...]] = None
):
@classmethod 的说明
@classmethod
def from_pretrained(cls,pretrained_model_name_or_path: Union[str, os.PathLike],*init_inputs,cache_dir: Optional[Union[str, os.PathLike]] = None,force_download: bool = False,local_files_only: bool = False,token: Optional[Union[str, bool]] = None,revision: str = "main",trust_remote_code=False,**kwargs,
):............

此方法是类的方法,不需要实例化就能访问,且第一个参数是类(cls),而不是对象(self)。此方法可以访问类属性和cls的方法,而不能访问self的方法。

with torch.no_grad() 的作用

torch.no_grad()是PyTorch中的一个上下文管理器(context manager),用于指定在其内部的代码块中不进行梯度计算。当你不需要计算梯度时,可以使用该上下文管理器来提高代码的执行效率,尤其是在推断(inference)阶段和梯度裁剪(grad clip)阶段的时候。不需要进行梯度计算和反向传播,只需要进行前向传播计算。,从而提高计算效率并节省内存。with torch.no_grad()常见于eval()验证集和测试集中。另外,This context manager is thread local; it will not affect computation in other threads.

logits

在神经网络中,logits通常是指模型在最后一层(全连接层)产生的原始输出,该层有多少个神经元就会有多少个值,这些输出还没有经过任何激活函数(如softmax或sigmoid)处理,根据不同的目的,将这些值输入到不同的激活函数中,就能归纳出不同的结果。
比如在多分类任务中,我们使用 logits.argmax(1)来得到预测的 label_id,也就是分类id。
其中torch.argmax(dim)函数的意思是返回最大值对应的索引,dim不指定任何参数就是指的所有元素;dim指定为0时求得是列的argmax;dim指定为1时求得是行的argmax;因为 torch 支持批量喂数据,所以很多地方得到的结果都是 [batch_size, n] 维的矩阵,batch_size 就是批的大小,相当于将这些样本的结果一行一行堆起来了,所以 dim = 1 就是逐个样本的求argmax。
比如在train的时候会按批(epoch)计算准确度

acc = (logits.argmax(1) == label).float().mean()'''
(logits.argmax(1) == label).float() 得到 batch_size 个 0,1,0,1...
然后使用 mean() 求平均值,而这正好就是 1 出现的频率,即准确度
'''

相关文章:

transformers 框架使用详解,bert-base-chinese

以 bert-base-chinese 模型为例&#xff0c;模型目录 model_name "C:/Users/Administrator.DESKTOP-TPJL4TC/.cache/modelscope/hub/tiansz/bert-base-chinese" bert-base-chinese 模型大小只有400多兆&#xff0c;参数的量级在百万级别&#xff0c;与现在动辄几十…...

STM32——ADC

目录 1、ADC的介绍 2、ADC主要特征 3、ADC结构与引脚 4、ADC配置流程 5、示例&#xff08;光敏电阻的ADC采样&#xff09; 6、提示 7、结语&#xff1a; 1、ADC的介绍 12位ADC是一种逐次逼近型模拟数字转换器。它有多达18个通道&#xff0c;可测量16个外部和2个内部 信号…...

Unity SRP学习笔记(二)

Unity SRP学习笔记&#xff08;二&#xff09; 主要参考&#xff1a; https://catlikecoding.com/unity/tutorials/custom-srp/ https://docs.unity.cn/cn/2022.3/ScriptReference/index.html 中文教程部分参考&#xff08;可选&#xff09;&#xff1a; https://tuncle.blog/c…...

数据库第五次作业

一要求 二建库建表 触发器 存储过程 三查询 触发器 1 建立触发器&#xff0c;订单表中增加订单数量后&#xff0c;商品表商品数量同步减少对应的商品订单出数量,并测试 测试 2 建立触发器&#xff0c;实现功能:客户取消订单&#xff0c;恢复商品表对应商品的数量 测试 3…...

健身房业务流程优化:SpringBoot解决方案

3系统分析 3.1可行性分析 通过对本健身房管理系统实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本健身房管理系统采用SSM框架&#xff0c;JAVA作为开发语言&a…...

【产品经理】工业互联网企业上市之路

树根互联2022年6月2日提交招股书之后&#xff0c;因财务资料超过六个月有效期加三个月延长期&#xff0c;2022年9月30日上市审核中止&#xff1b;2022年12月26日树根互联更新了2022年半年度财务资料&#xff0c;又九个月过去了&#xff0c;其上市进程将面临再一次中止。 处于上…...

Java学习教程,从入门到精通,Java对象和类语法知识点(20)

1、Java对象和类语法知识点 类的定义 使用class关键字定义类。类名通常使用大写驼峰命名法&#xff08;PascalCase&#xff09;。类与对象 类是创建对象的模板或蓝图&#xff0c;它定义了对象的属性和行为。对象是类的实例&#xff0c;它包含了类定义的数据&#xff08;属性&am…...

金融场中的量化交易:民锋数据驱动策略的优势解析市

随着科技的发展&#xff0c;量化交易成为金融市场的重要组成部分。民锋公司通过智能算法和大数据分析&#xff0c;设计了一系列量化交易策略&#xff0c;帮助投资者实现科学投资。本文将探讨民锋在数据驱动策略上的优势&#xff0c;并展示如何通过量化模型在复杂的市场中获得收…...

Docker 配置镜像加速

docker 拉取代码时出现 ERROR: failed to solve: node:16: unexpected status from HEAD request to https:// xxxxxx.mirror.aliyuncs.com/v2/library/node/m…...

HTTP慢速攻击原理及解决办法

目录 引言 HTTP慢速攻击原理 解决办法 Nginx Tomcat 华宇TAS IIS 结论 引言 HTTP慢速攻击&#xff08;Slow HTTP Attack&#xff09;是一种拒绝服务攻击&#xff08;DoS&#xff09;&#xff0c;攻击者通过故意缓慢地发送HTTP请求来耗尽服务器资源&#xff0c;导致合法…...

【系统面试篇】进程和线程类(1)(笔记)——区别、通讯方式、同步、互斥、锁分类

目录 一、问题综述 1. 进程和线程的区别&#xff1f; 2. 进程的状态有哪些&#xff1f; 3. 进程之间的通信方式? &#xff08;1&#xff09;管道 &#xff08;2&#xff09;消息队列 &#xff08;3&#xff09;共享内存 &#xff08;4&#xff09;信号量 &#xff08…...

[C++]——哈希(附源码)

目录 ​编辑 ​编辑 一、前言 二、正文 2.1 unorder系列关联式容器 2.1.1 unordered_map 2.1.1.1 unorderer_map的介绍 ①unordered_map的构造 ②unordered_map的容量 ③unordered_map的迭代器 ④unordered_map的元素访问 ⑤unordered_map的查询 ⑥unordered_map的修改操…...

2024中国自动化大会(CAC2024)“智慧化工及复合人才培养”平行会议圆满落幕

2024中国自动化大会于11月1-3日在青岛举行&#xff0c;本次大会由中国自动化学会主办&#xff0c;青岛科技大学&#xff08;简称“青科大”&#xff09;承办。北京和隆优化科技股份有限公司&#xff08;简称“和隆优化”&#xff09;承办了重要的“智慧化工及复合人才培养”平行…...

计算机毕业设计——ssm基于JAVA的求职招聘网站的设计与实现演示录像 2021

作者&#xff1a;程序媛9688开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等。 &#x1f31f;文末获取源码数据库&#x1f31f;感兴趣的可以先收藏起来&#xff0c;还有大家在毕设选题&#xff08;免费咨询指导选题&#xff09;&#xff0…...

跨平台Flutter 、ReactNative 开发原理

一、跨平台Flutter开发原理 Flutter是一个跨平台的应用程序开发框架&#xff0c;它允许你使用一组代码库来构建同时运行在Android和iOS上的应用程序。 1.1.Flutter的核心原理基于以下几点&#xff1a; Dart异步、Widget构建块灵活配置、自工化工具链、热重载、Skia图库、Dar…...

qt QToolBar详解

1、概述 QToolBar是Qt框架中的一个控件&#xff0c;用于在工具栏中显示一组操作按钮和其他控件。它提供了一种方便的方式来组织和管理应用程序中的工具和操作。工具栏通常位于软件或应用程序界面的上方&#xff0c;包含一系列常用工具和命令按钮&#xff0c;用于快速访问和执行…...

MongoDB基础介绍以及从0~1语法介绍

目录 MongoDB 教程导读 NoSQL 简介 关系型数据库遵循ACID规则 分布式系统 分布式计算的优点 分布式计算的缺点 什么是NoSQL? 为什么使用NoSQL ? RDBMS vs NoSQL NoSQL 简史 CAP定理&#xff08;CAP theorem&#xff09; NoSQL的优点/缺点 BASE ACID vs BASE N…...

利用Docker Compose构建微服务架构

&#x1f493; 博客主页&#xff1a;瑕疵的CSDN主页 &#x1f4dd; Gitee主页&#xff1a;瑕疵的gitee主页 ⏩ 文章专栏&#xff1a;《热点资讯》 利用Docker Compose构建微服务架构 引言 Docker Compose 简介 安装 Docker Compose 创建项目结构 编写 Dockerfile 前端 Dockerf…...

数据中台一键大解析!

自从互联玩企业掀起了数据中台风&#xff0c;数据中台这个点马上就火起来了&#xff0c;短短几年数据中台就得到了极高的热度&#xff0c;一大堆企业也在跟风做数据中台&#xff0c;都把数据中台作为企业数字化转型的救命稻草&#xff0c;可是如果我告诉你数据中台并不是万能钥…...

MySQL45讲 第十六讲 “order by”是怎么工作的?

文章目录 MySQL45讲 第十六讲 “order by”是怎么工作的&#xff1f;一、引言二、全字段排序&#xff08;一&#xff09;索引创建与执行情况分析&#xff08;二&#xff09;执行流程&#xff08;三&#xff09;查看是否使用临时文件 三、rowid 排序&#xff08;一&#xff09;参…...

RestClient

什么是RestClient RestClient 是 Elasticsearch 官方提供的 Java 低级 REST 客户端&#xff0c;它允许HTTP与Elasticsearch 集群通信&#xff0c;而无需处理 JSON 序列化/反序列化等底层细节。它是 Elasticsearch Java API 客户端的基础。 RestClient 主要特点 轻量级&#xff…...

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

大话软工笔记—需求分析概述

需求分析&#xff0c;就是要对需求调研收集到的资料信息逐个地进行拆分、研究&#xff0c;从大量的不确定“需求”中确定出哪些需求最终要转换为确定的“功能需求”。 需求分析的作用非常重要&#xff0c;后续设计的依据主要来自于需求分析的成果&#xff0c;包括: 项目的目的…...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

Vue3 + Element Plus + TypeScript中el-transfer穿梭框组件使用详解及示例

使用详解 Element Plus 的 el-transfer 组件是一个强大的穿梭框组件&#xff0c;常用于在两个集合之间进行数据转移&#xff0c;如权限分配、数据选择等场景。下面我将详细介绍其用法并提供一个完整示例。 核心特性与用法 基本属性 v-model&#xff1a;绑定右侧列表的值&…...

【AI学习】三、AI算法中的向量

在人工智能&#xff08;AI&#xff09;算法中&#xff0c;向量&#xff08;Vector&#xff09;是一种将现实世界中的数据&#xff08;如图像、文本、音频等&#xff09;转化为计算机可处理的数值型特征表示的工具。它是连接人类认知&#xff08;如语义、视觉特征&#xff09;与…...

反射获取方法和属性

Java反射获取方法 在Java中&#xff0c;反射&#xff08;Reflection&#xff09;是一种强大的机制&#xff0c;允许程序在运行时访问和操作类的内部属性和方法。通过反射&#xff0c;可以动态地创建对象、调用方法、改变属性值&#xff0c;这在很多Java框架中如Spring和Hiberna…...

04-初识css

一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...

leetcodeSQL解题:3564. 季节性销售分析

leetcodeSQL解题&#xff1a;3564. 季节性销售分析 题目&#xff1a; 表&#xff1a;sales ---------------------- | Column Name | Type | ---------------------- | sale_id | int | | product_id | int | | sale_date | date | | quantity | int | | price | decimal | -…...

实现弹窗随键盘上移居中

实现弹窗随键盘上移的核心思路 在Android中&#xff0c;可以通过监听键盘的显示和隐藏事件&#xff0c;动态调整弹窗的位置。关键点在于获取键盘高度&#xff0c;并计算剩余屏幕空间以重新定位弹窗。 // 在Activity或Fragment中设置键盘监听 val rootView findViewById<V…...