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

自然语言处理从入门到应用——LangChain:记忆(Memory)-[记忆的类型Ⅰ]

分类目录:《自然语言处理从入门到应用》总目录


会话缓存记忆ConversationBufferMemory

本节将介绍如何使用对话缓存记忆ConversationBufferMemory。这种记忆方式允许存储消息,并将消息提取到一个变量中,我们首先将其提取为字符串:

from langchain.memory import ConversationBufferMemorymemory = ConversationBufferMemory()
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.load_memory_variables({})

输出:

{'history': 'Human: hi\nAI: whats up'}

我们还可以将历史记录作为消息列表获取。如果我们与聊天模型一起使用,这非常有用:

memory = ConversationBufferMemory(return_messages=True)
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.load_memory_variables({})

输出:

{'history': [HumanMessage(content='hi', additional_kwargs={}),AIMessage(content='whats up', additional_kwargs={})]}
在链式结构中使用

我们还可以在链式结构中使用它,设置verbose=True以便我们可以看到提示:

from langchain.llms import OpenAI
from langchain.chains import ConversationChainllm = OpenAI(temperature=0)
conversation = ConversationChain(llm=llm, verbose=True, memory=ConversationBufferMemory()
)
conversation.predict(input="Hi there!")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:Human: Hi there!
AI:> Finished chain.

输出:

" Hi there! It's nice to meet you. How can I help you today?"

输入:

conversation.predict(input="I'm doing well! Just having a conversation with an AI.")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:
Human: Hi there!
AI:  Hi there! It's nice to meet you. How can I help you today?
Human: I'm doing well! Just having a conversation with an AI.
AI:> Finished chain.

输出:

" That's great! It's always nice to have a conversation with someone new. What would you like to talk about?"

输入:

conversation.predict(input="Tell me about yourself.")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:
Human: Hi there!
AI:  Hi there! It's nice to meet you. How can I help you today?
Human: I'm doing well! Just having a conversation with an AI.
AI:  That's great! It's always nice to have a conversation with someone new. What would you like to talk about?
Human: Tell me about yourself.
AI:> Finished chain.

输出:

" Sure! I'm an AI created to help people with their everyday tasks. I'm programmed to understand natural language and provide helpful information. I'm also constantly learning and updating my knowledge base so I can provide more accurate and helpful answers."

会话缓存记忆ConversationBufferWindowMemory

会话缓存记忆ConversationBufferWindowMemory保留了对话中随时间变化的交互列表。它只使用最后的 K K K次交互。这对于保持最近交互的滑动窗口很有用,以防止缓冲区过大。

from langchain.memory import ConversationBufferWindowMemorymemory = ConversationBufferWindowMemory(k=1)
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.save_context({"input": "not much you"}, {"output": "not much"})
memory.load_memory_variables({})

输出:

{'history': 'Human: not much you\nAI: not much'}

我们还可以将历史记录作为消息列表获取,如果我们将其与聊天模型一起使用,这将非常有用:

memory = ConversationBufferWindowMemory(k=1, return_messages=True)memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.save_context({"input": "not much you"}, {"output": "not much"})
memory.load_memory_variables({})

输出:

{'history': [HumanMessage(content='not much you', additional_kwargs={}),
AIMessage(content='not much', additional_kwargs={})]}
Using in a chain

在下面的示例中再次设置verbose=True以便查看提示:

from langchain.llms import OpenAI
from langchain.chains import ConversationChainconversation_with_summary = ConversationChain(llm=OpenAI(temperature=0), memory=ConversationBufferWindowMemory(k=2), verbose=True
)conversation_with_summary.predict(input="Hi, what's up?")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:Human: Hi, what's up?
AI:> Finished chain.

输出:

" Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?"

输入:

conversation_with_summary.predict(input="What's their issues?")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:
Human: Hi, what's up?
AI:  Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?
Human: What's their issues?
AI:> Finished chain.

输出:

" The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected."

输入:

conversation_with_summary.predict(input="Is it going well?")

输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:
Human: Hi, what's up?
AI:  Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?
Human: What's their issues?
AI:  The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected.
Human: Is it going well?
AI:> Finished chain.

输出:

" Yes, it's going well so far. We've already identified the problem and are now working on a solution."

当前,若继续对话则" Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?"的记忆将被遗忘:

conversation_with_summary.predict(input="What's the solution?")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:
Human: What's their issues?
AI:  The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected.
Human: Is it going well?
AI:  Yes, it's going well so far. We've already identified the problem and are now working on a solution.
Human: What's the solution?
AI:> Finished chain.

输出:

" The solution is to reset the router and reconfigure the settings. We're currently in the process of doing that."

实体记忆(Entity Memory)

本节演示了如何使用一个记忆模块来记录有关特定实体的信息。它使用语言模型(LLMs)提取实体相关的信息,并随着时间的推移逐渐积累对该实体的知识。让我们首先通过一个例子来了解如何使用这个功能:

from langchain.llms import OpenAI
from langchain.memory import ConversationEntityMemoryllm = OpenAI(temperature=0)
memory = ConversationEntityMemory(llm=llm)
_input = {"input": "Deven & Sam are working on a hackathon project"}
memory.load_memory_variables(_input)
memory.save_context(_input,{"output": " That sounds like a great project! What kind of project are they working on?"}
)
memory.load_memory_variables({"input": 'who is Sam'})

输出:

{'history': 'Human: Deven & Sam are working on a hackathon project\nAI:  That sounds like a great project! What kind of project are they working on?',
'entities': {'Sam': 'Sam is working on a hackathon project with Deven.'}}

输入:

memory = ConversationEntityMemory(llm=llm, return_messages=True)
_input = {"input": "Deven & Sam are working on a hackathon project"}
memory.load_memory_variables(_input)
memory.save_context(_input,{"output": " That sounds like a great project! What kind of project are they working on?"}
)
memory.load_memory_variables({"input": 'who is Sam'})

输出:

{'history': [HumanMessage(content='Deven & Sam are working on a hackathon project', additional_kwargs={}),
AIMessage(content=' That sounds like a great project! What kind of project are they working on?', additional_kwargs={})], 
'entities': {'Sam': 'Sam is working on a hackathon project with Deven.'}}
在链中调用
from langchain.chains import ConversationChain
from langchain.memory import ConversationEntityMemory
from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
from pydantic import BaseModel
from typing import List, Dict, Any
conversation = ConversationChain(llm=llm, verbose=True,prompt=ENTITY_MEMORY_CONVERSATION_TEMPLATE,memory=ConversationEntityMemory(llm=llm)
)conversation.predict(input="Deven & Sam are working on a hackathon project")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Deven': 'Deven is working on a hackathon project with Sam.', 'Sam': 'Sam is working on a hackathon project with Deven.'}Current conversation:Last line:
Human: Deven & Sam are working on a hackathon project
You:> Finished chain.

输出:

' That sounds like a great project! What kind of project are they working on?'

输入:

conversation.memory.entity_store.store

输出:

{'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon.',
'Sam': 'Sam is working on a hackathon project with Deven.'}

输入:

conversation.predict(input="They are trying to add more complex memory structures to Langchain")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon.', 'Sam': 'Sam is working on a hackathon project with Deven.', 'Langchain': ''}Current conversation:
Human: Deven & Sam are working on a hackathon project
AI:  That sounds like a great project! What kind of project are they working on?
Last line:
Human: They are trying to add more complex memory structures to Langchain
You:> Finished chain.

输出:

' That sounds like an interesting project! What kind of memory structures are they trying to add?'

输入:

conversation.predict(input="They are adding in a key-value store for entities mentioned so far in the conversation.")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon. They are trying to add more complex memory structures to Langchain.', 'Sam': 'Sam is working on a hackathon project with Deven, trying to add more complex memory structures to Langchain.', 'Langchain': 'Langchain is a project that is trying to add more complex memory structures.', 'Key-Value Store': ''}Current conversation:
Human: Deven & Sam are working on a hackathon project
AI:  That sounds like a great project! What kind of project are they working on?
Human: They are trying to add more complex memory structures to Langchain
AI:  That sounds like an interesting project! What kind of memory structures are they trying to add?
Last line:
Human: They are adding in a key-value store for entities mentioned so far in the conversation.
You:> Finished chain.

输出:

' That sounds like a great idea! How will the key-value store help with the project?'

输入:

conversation.predict(input="What do you know about Deven & Sam?")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon. They are trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation.', 'Sam': 'Sam is working on a hackathon project with Deven, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation.'}Current conversation:
Human: Deven & Sam are working on a hackathon project
AI:  That sounds like a great project! What kind of project are they working on?
Human: They are trying to add more complex memory structures to Langchain
AI:  That sounds like an interesting project! What kind of memory structures are they trying to add?
Human: They are adding in a key-value store for entities mentioned so far in the conversation.
AI:  That sounds like a great idea! How will the key-value store help with the project?
Last line:
Human: What do you know about Deven & Sam?
You:> Finished chain.

输出:

' Deven and Sam are working on a hackathon project together, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation. They seem to be working hard on this project and have a great idea for how the key-value store can help.'
检查记忆存储

我们也可以直接检查记忆存储。在下面的示例中,我们直接查看它,然后通过一些添加信息的示例来观察它的变化。

from pprint import pprint
pprint(conversation.memory.entity_store.store)

输出:

{'Daimon': 'Daimon is a company founded by Sam, a successful entrepreneur.','Deven': 'Deven is working on a hackathon project with Sam, which they are ''entering into a hackathon. They are trying to add more complex ''memory structures to Langchain, including a key-value store for ''entities mentioned so far in the conversation, and seem to be ''working hard on this project with a great idea for how the ''key-value store can help.','Key-Value Store': 'A key-value store is being added to the project to store ''entities mentioned in the conversation.','Langchain': 'Langchain is a project that is trying to add more complex ''memory structures, including a key-value store for entities ''mentioned so far in the conversation.','Sam': 'Sam is working on a hackathon project with Deven, trying to add more ''complex memory structures to Langchain, including a key-value store ''for entities mentioned so far in the conversation. They seem to have ''a great idea for how the key-value store can help, and Sam is also ''the founder of a company called Daimon.'}

输出:

conversation.predict(input="Sam is the founder of a company called Daimon.")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Daimon': 'Daimon is a company founded by Sam, a successful entrepreneur.', 'Sam': 'Sam is working on a hackathon project with Deven, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation. They seem to have a great idea for how the key-value store can help, and Sam is also the founder of a company called Daimon.'}Current conversation:
Human: They are adding in a key-value store for entities mentioned so far in the conversation.
AI:  That sounds like a great idea! How will the key-value store help with the project?
Human: What do you know about Deven & Sam?
AI:  Deven and Sam are working on a hackathon project together, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation. They seem to be working hard on this project and have a great idea for how the key-value store can help.
Human: Sam is the founder of a company called Daimon.
AI: 
That's impressive! It sounds like Sam is a very successful entrepreneur. What kind of company is Daimon?
Last line:
Human: Sam is the founder of a company called Daimon.
You:> Finished chain.

输出:

" That's impressive! It sounds like Sam is a very successful entrepreneur. What kind of company is Daimon?"

输入:

from pprint import pprint
pprint(conversation.memory.entity_store.store)

输出:

{'Daimon': 'Daimon is a company founded by Sam, a successful entrepreneur, who ''is working on a hackathon project with Deven to add more complex ''memory structures to Langchain.','Deven': 'Deven is working on a hackathon project with Sam, which they are ''entering into a hackathon. They are trying to add more complex ''memory structures to Langchain, including a key-value store for ''entities mentioned so far in the conversation, and seem to be ''working hard on this project with a great idea for how the ''key-value store can help.','Key-Value Store': 'A key-value store is being added to the project to store ''entities mentioned in the conversation.','Langchain': 'Langchain is a project that is trying to add more complex ''memory structures, including a key-value store for entities ''mentioned so far in the conversation.','Sam': 'Sam is working on a hackathon project with Deven, trying to add more ''complex memory structures to Langchain, including a key-value store ''for entities mentioned so far in the conversation. They seem to have ''a great idea for how the key-value store can help, and Sam is also ''the founder of a successful company called Daimon.'}

输入:

conversation.predict(input="What do you know about Sam?")

日志输出:

> Entering new ConversationChain chain...
Prompt after formatting:
You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context:
{'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon. They are trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation, and seem to be working hard on this project with a great idea for how the key-value store can help.', 'Sam': 'Sam is working on a hackathon project with Deven, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation. They seem to have a great idea for how the key-value store can help, and Sam is also the founder of a successful company called Daimon.', 'Langchain': 'Langchain is a project that is trying to add more complex memory structures, including a key-value store for entities mentioned so far in the conversation.', 'Daimon': 'Daimon is a company founded by Sam, a successful entrepreneur, who is working on a hackathon project with Deven to add more complex memory structures to Langchain.'}Current conversation:
Human: What do you know about Deven & Sam?
AI:  Deven and Sam are working on a hackathon project together, trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation. They seem to be working hard on this project and have a great idea for how the key-value store can help.
Human: Sam is the founder of a company called Daimon.
AI: 
That's impressive! It sounds like Sam is a very successful entrepreneur. What kind of company is Daimon?
Human: Sam is the founder of a company called Daimon.
AI:  That's impressive! It sounds like Sam is a very successful entrepreneur. What kind of company is Daimon?
Last line:
Human: What do you know about Sam?
You:> Finished chain.

输出:

' Sam is the founder of a successful company called Daimon. He is also working on a hackathon project with Deven to add more complex memory structures to Langchain. They seem to have a great idea for how the key-value store can help.'

参考文献:
[1] LangChain官方网站:https://www.langchain.com/
[2] LangChain 🦜️🔗 中文网,跟着LangChain一起学LLM/GPT开发:https://www.langchain.com.cn/
[3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架:http://www.cnlangchain.com/

相关文章:

自然语言处理从入门到应用——LangChain:记忆(Memory)-[记忆的类型Ⅰ]

分类目录:《自然语言处理从入门到应用》总目录 会话缓存记忆ConversationBufferMemory 本节将介绍如何使用对话缓存记忆ConversationBufferMemory。这种记忆方式允许存储消息,并将消息提取到一个变量中,我们首先将其提取为字符串&#xff1a…...

Camunda 7.x 系列【7】Spring Boot 集成 Camunda 7.19

有道无术,术尚可求,有术无道,止于术。 本系列Spring Boot 版本 2.7.9 本系列Camunda 版本 7.19.0 源码地址:https://gitee.com/pearl-organization/camunda-study-demo 文章目录 1. 前言2. Camunda Platform Run3. Spring Boot 版本兼容性4. 集成 Spring Boot5. 启动项目…...

24华东交通软件工程837考研题库

1.Jackson设计方法是由英国的M.Jackson所提出的。它是一种面向( )的软件设 计方法。 A.对象 B.数据流 C.数据结构 D.控制结构 答案:C 2.软件设计中,Jackson方法是一种面向…...

nginx 以及nginx优化

目录 nginx功能介绍 静态文件服务 反向代理 动态内容处理 SSL/TLS 加密支持 虚拟主机支持 URL 重写和重定向 缓存机制 日志记录 可扩展性和灵活性 nginx的主要应用场景 nginx常用命令 nginx另外一种安装方式 nginx常用的信号符: nginx配置文件详解 n…...

cesium学习记录04-坐标系

一、地理坐标系和投影坐标系的关系 地理坐标系 (Geographic Coordinate System, GCS) 定义:地理坐标系是一个基于三维地球表面的坐标系统。它使用经度和纬度来表示地点的位置。 特点: 使用经纬度来定义位置。 基于特定的地球参考椭球体。 适用于全球范…...

P5737 【深基7.例3】闰年展示

题目描述 输入 x , y x,y x,y,输出 [ x , y ] [x,y] [x,y] 区间中闰年个数,并在下一行输出所有闰年年份数字,使用空格隔开。 输入格式 输入两个正整数 x , y x,y x,y,以空格隔开。 输出格式 第一行输出一个正整数&#xf…...

Nacos的安装使用教程Linux

在 Linux 操作系统上安装和使用 Nacos 与 Windows 类似,以下是详细的步骤教程。我们将使用 Nacos 的 Standalone 模式进行安装和使用。请注意,对于生产环境,建议使用集群模式来实现高可用性和可扩展性。 步骤 1:准备环境 Java 安…...

数据结构-学习

参考: 数据结构-学习笔记_蓝净云_蓝净云的博客-CSDN博客...

【MFC】05.MFC六大机制:程序启动机制-笔记

MFC程序开发所谓是非常简单,但是对于我们逆向人员来说,如果想要逆向MFC程序,那么我们就必须了解它背后的机制,这样我们才能够清晰地逆向出MFC程序,今天这篇文章就来带领大家了解MFC的第一大机制:程序启动机…...

Von Maur, Inc EDI 需求分析

Von Maur, Inc 是一家历史悠久的卖场,成立于19世纪,总部位于美国。作为一家知名的零售商,Von Maur 主要经营高端时装、家居用品和美妆产品。其使命是为顾客提供优质的产品和无与伦比的购物体验。多年来,Von Maur 凭借其卓越的服务…...

[深度学习入门]PyTorch深度学习[Numpy基础](上)

目录 一、前言二、Numpy概述三、生成Numpy数组3.1 从已有数据中创建数组3.2 利用random模块生成数组3.3 创建特定形状的多维数组3.4 利用arange和linspace函数生成数组 四、获取元素五、Numpy的算术运算5.1 对应元素相乘5.2 点积运算 六、后记 本文的目标受众: 对机…...

Excel vost 实现照光灯效果

如果你想要在 VSTO(Visual Studio Tools for Office)中实现在 Excel 中添加“照光灯”效果,你需要创建一个 VSTO 插件来实现这个功能。照光灯效果通常是指通过将非活动行或列进行高亮显示,以便更清楚地查看某一行或列的内容。以下…...

IntelliJ中文乱码问题

1、控制台乱码 运行时控制台输出的中文为乱码,解决方法:帮助 > 编辑自定义虚拟机选项… > 此时会自动创建出一个新文件,输入:-Dfile.encodingUTF-8,然后重启IDE即可,操作截图如下: 2、…...

【C++】红黑树模拟实现插入功能(包含旋转和变色)

红黑树模拟实现并封装为map和set 前言正式开始红黑树概念红黑树基本要求大致框架树节点树 调整红黑树使其平衡第一种:cur红,p红,g黑,u存在且为红第二种:cur红,p红,g黑,u不存在或为黑…...

Pads输出器件坐标文件时,如何更改器件坐标精度

相信对于用pads软件的工程师么,在完成PCB设计的时候都需要输出生产文件给板厂和贴片厂,今天我们需要给大家介绍的是如何在在pads软件上面输出器件坐标文件以及如何更改器件坐标文件的精度。 首先我们需要点击工具-基本脚本-基本脚本接下来会跳到下面这个…...

Vuejs3父组传值给子组件

父组件代码 <script setup> import TextProps from ./components/TextProps.vue; import { reactive } from vue;const queryobj reactive({"a":1, "b":1}); const aryobj reactive([1,2,3]);</script><template><div class"…...

竞赛项目 深度学习的智能中文对话问答机器人

文章目录 0 简介1 项目架构2 项目的主要过程2.1 数据清洗、预处理2.2 分桶2.3 训练 3 项目的整体结构4 重要的API4.1 LSTM cells部分&#xff1a;4.2 损失函数&#xff1a;4.3 搭建seq2seq框架&#xff1a;4.4 测试部分&#xff1a;4.5 评价NLP测试效果&#xff1a;4.6 梯度截断…...

【剑指 の 精选】热门状态机 DP 运用题

题目描述 这是 LeetCode 上的 「剑指 Offer II 091. 粉刷房子」 &#xff0c;难度为 「中等」。 Tag : 「状态机 DP」、「动态规划」 假如有一排房子&#xff0c;共 n 个&#xff0c;每个房子可以被粉刷成红色、蓝色或者绿色这三种颜色中的一种&#xff0c;你需要粉刷所有的房子…...

自动化实践-全量Json对比在技改需求提效实践

1 背景 随着自动化测试左移实践深入&#xff0c;越来越多不同类型的需求开始用自动化测试左移来实践&#xff0c;在实践的过程中也有了新的提效诉求&#xff0c;比如技改类的服务拆分项目或者BC流量拆分的项目&#xff0c;在实践过程中&#xff0c;这类需求会期望不同染色环境…...

【Matlab】PSO优化(单隐层)BP神经网络

上一篇博客介绍了BP-GA&#xff1a;BP神经网络遗传算法(BP-GA)函数极值寻优——非线性函数求极值&#xff0c;本篇博客将介绍用PSO&#xff08;粒子群优化算法&#xff09;优化BP神经网络。 1.优化思路 BP神经网络的隐藏节点通常由重复的前向传递和反向传播的方式来决定&#…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)

参考官方文档&#xff1a;https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java&#xff08;供 Kotlin 使用&#xff09; 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

React---day11

14.4 react-redux第三方库 提供connect、thunk之类的函数 以获取一个banner数据为例子 store&#xff1a; 我们在使用异步的时候理应是要使用中间件的&#xff0c;但是configureStore 已经自动集成了 redux-thunk&#xff0c;注意action里面要返回函数 import { configureS…...

C#中的CLR属性、依赖属性与附加属性

CLR属性的主要特征 封装性&#xff1a; 隐藏字段的实现细节 提供对字段的受控访问 访问控制&#xff1a; 可单独设置get/set访问器的可见性 可创建只读或只写属性 计算属性&#xff1a; 可以在getter中执行计算逻辑 不需要直接对应一个字段 验证逻辑&#xff1a; 可以…...

Proxmox Mail Gateway安装指南:从零开始配置高效邮件过滤系统

&#x1f49d;&#x1f49d;&#x1f49d;欢迎莅临我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐&#xff1a;「storms…...

Scrapy-Redis分布式爬虫架构的可扩展性与容错性增强:基于微服务与容器化的解决方案

在大数据时代&#xff0c;海量数据的采集与处理成为企业和研究机构获取信息的关键环节。Scrapy-Redis作为一种经典的分布式爬虫架构&#xff0c;在处理大规模数据抓取任务时展现出强大的能力。然而&#xff0c;随着业务规模的不断扩大和数据抓取需求的日益复杂&#xff0c;传统…...

MyBatis中关于缓存的理解

MyBatis缓存 MyBatis系统当中默认定义两级缓存&#xff1a;一级缓存、二级缓存 默认情况下&#xff0c;只有一级缓存开启&#xff08;sqlSession级别的缓存&#xff09;二级缓存需要手动开启配置&#xff0c;需要局域namespace级别的缓存 一级缓存&#xff08;本地缓存&#…...

Python 训练营打卡 Day 47

注意力热力图可视化 在day 46代码的基础上&#xff0c;对比不同卷积层热力图可视化的结果 import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms from torch.utils.data import DataLoader import matplotlib.pypl…...

一些实用的chrome扩展0x01

简介 浏览器扩展程序有助于自动化任务、查找隐藏的漏洞、隐藏自身痕迹。以下列出了一些必备扩展程序&#xff0c;无论是测试应用程序、搜寻漏洞还是收集情报&#xff0c;它们都能提升工作流程。 FoxyProxy 代理管理工具&#xff0c;此扩展简化了使用代理&#xff08;如 Burp…...

java高级——高阶函数、如何定义一个函数式接口类似stream流的filter

java高级——高阶函数、stream流 前情提要文章介绍一、函数伊始1.1 合格的函数1.2 有形的函数2. 函数对象2.1 函数对象——行为参数化2.2 函数对象——延迟执行 二、 函数编程语法1. 函数对象表现形式1.1 Lambda表达式1.2 方法引用&#xff08;Math::max&#xff09; 2 函数接口…...