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

【机器学习】机器学习与自然语言处理的融合应用与性能优化新探索

引言

自然语言处理(NLP)是计算机科学中的一个重要领域,旨在通过计算机对人类语言进行理解、生成和分析。随着深度学习和大数据技术的发展,机器学习在自然语言处理中的应用越来越广泛,从文本分类、情感分析到机器翻译和对话系统,都展示了强大的能力。本文将详细介绍机器学习在自然语言处理中的应用,包括数据预处理、模型选择、模型训练和性能优化。通过具体的案例分析,展示机器学习技术在自然语言处理中的实际应用,并提供相应的代码示例。
在这里插入图片描述

第一章:机器学习在自然语言处理中的应用

1.1 数据预处理

在自然语言处理应用中,数据预处理是机器学习模型成功的关键步骤。文本数据通常具有非结构化和高维度的特点,需要进行清洗、分词、去停用词和特征提取等处理。

1.1.1 数据清洗

数据清洗包括去除噪声、标点符号、HTML标签等无关内容。

import redef clean_text(text):# 去除HTML标签text = re.sub(r'<.*?>', '', text)# 去除标点符号text = re.sub(r'[^\w\s]', '', text)# 去除数字text = re.sub(r'\d+', '', text)# 转换为小写text = text.lower()return text# 示例文本
text = "<html>This is a sample text with 123 numbers and <b>HTML</b> tags.</html>"
cleaned_text = clean_text(text)
print(cleaned_text)
1.1.2 分词

分词是将文本拆分为单独的单词或词组,是自然语言处理中的基础步骤。

import nltk
from nltk.tokenize import word_tokenize# 下载NLTK数据包
nltk.download('punkt')# 分词
tokens = word_tokenize(cleaned_text)
print(tokens)
1.1.3 去停用词

停用词是指在文本处理中被过滤掉的常见词,如“的”、“是”、“在”等。去除停用词可以减少噪声,提高模型的训练效果。

from nltk.corpus import stopwords# 下载停用词数据包
nltk.download('stopwords')# 去停用词
stop_words = set(stopwords.words('english'))
filtered_tokens = [word for word in tokens if word not in stop_words]
print(filtered_tokens)
1.1.4 特征提取

特征提取将文本数据转换为数值特征,常用的方法包括词袋模型(Bag of Words)、TF-IDF和词嵌入(Word Embedding)等。

from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer# 词袋模型
vectorizer = CountVectorizer()
X_bow = vectorizer.fit_transform([' '.join(filtered_tokens)])
print(X_bow.toarray())# TF-IDF
tfidf_vectorizer = TfidfVectorizer()
X_tfidf = tfidf_vectorizer.fit_transform([' '.join(filtered_tokens)])
print(X_tfidf.toarray())

1.2 模型选择

在自然语言处理中,常用的机器学习模型包括朴素贝叶斯、支持向量机(SVM)、循环神经网络(RNN)、长短期记忆网络(LSTM)和Transformer等。不同模型适用于不同的任务和数据特征,需要根据具体应用场景进行选择。

1.2.1 朴素贝叶斯

朴素贝叶斯适用于文本分类任务,特别是新闻分类和垃圾邮件检测等场景。

from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split# 数据分割
X = X_tfidf
y = [1]  # 示例标签
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# 训练朴素贝叶斯模型
model = MultinomialNB()
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
1.2.2 支持向量机

支持向量机适用于文本分类任务,特别是在高维数据和小样本数据中表现优异。

from sklearn.svm import SVC# 训练支持向量机模型
model = SVC()
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
1.2.3 循环神经网络

循环神经网络(RNN)适用于处理序列数据,能够捕捉文本中的上下文信息,常用于文本生成和序列标注任务。

from keras.models import Sequential
from keras.layers import SimpleRNN, Dense# 构建循环神经网络模型
model = Sequential()
model.add(SimpleRNN(50, activation='relu', input_shape=(X_train.shape[1], 1)))
model.add(Dense(1, activation='sigmoid'))# 编译模型
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])# 训练模型
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.2)
1.2.4 长短期记忆网络

长短期记忆网络(LSTM)是RNN的一种改进版本,能够有效解决长距离依赖问题,适用于文本生成、序列标注和机器翻译等任务。

from keras.layers import LSTM# 构建长短期记忆网络模型
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(X_train.shape[1], 1)))
model.add(Dense(1, activation='sigmoid'))# 编译模型
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])# 训练模型
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.2)
1.2.5 Transformer

Transformer是近年来在自然语言处理领域取得突破性进展的模型,广泛应用于机器翻译、文本生成和问答系统等任务。

from transformers import BertTokenizer, TFBertForSequenceClassification
from tensorflow.keras.optimizers import Adam# 加载预训练的BERT模型和分词器
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = TFBertForSequenceClassification.from_pretrained('bert-base-uncased')# 编译模型
optimizer = Adam(learning_rate=3e-5)
model.compile(optimizer=optimizer, loss=model.compute_loss, metrics=['accuracy'])# 数据预处理
train_encodings = tokenizer(list(X_train), truncation=True, padding=True, max_length=128)
test_encodings = tokenizer(list(X_test), truncation=True, padding=True, max_length=128)# 训练模型
model.fit(dict(train_encodings), y_train, epochs=3, batch_size=32, validation_data=(dict(test_encodings), y_test))

在这里插入图片描述

1.3 模型训练

模型训练是机器学习的核心步骤,通过优化算法最小化损失函数,调整模型参数,使模型在训练数据上表现良好。常见的优化算法包括梯度下降、随机梯度下降和Adam优化器等。

1.3.1 梯度下降

梯度下降通过计算损失函数对模型参数的导数,逐步调整参数,使损失函数最小化。

import numpy as np# 定义损失函数
def loss_function(y_true, y_pred):return np.mean((y_true - y_pred) ** 2)# 梯度下降优化
def gradient_descent(X, y, learning_rate=0.01, epochs=1000):m, n = X.shapetheta = np.zeros(n)for epoch in range(epochs):gradient = (1/m) * X.T.dot(X.dot(theta) - y)theta -= learning_rate * gradientreturn theta# 训练模型
theta = gradient_descent(X_train, y_train)
1.3.2 随机梯度下降

随机梯度下降在每次迭代中使用一个样本进行参数更新,具有较快的收敛速度和更好的泛化能力。

def stochastic_gradient_descent(X, y, learning_rate=0.01, epochs=1000):m, n = X.shapetheta = np.zeros(n)for epoch in range(epochs):for i in range(m):gradient = X[i].dot(theta) - y[i]theta -= learning_rate * gradient * X[i]return theta# 训练模型
theta = stochastic_gradient_descent(X_train, y_train)
1.3.3 Adam优化器

Adam优化器结合了动量和自适应学习率的优

点,能够快速有效地优化模型参数。

from keras.optimizers import Adam# 编译模型
model.compile(optimizer=Adam(learning_rate=0.001), loss='binary_crossentropy', metrics=['accuracy'])# 训练模型
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.2)

1.4 模型评估与性能优化

模型评估是衡量模型在测试数据上的表现,通过计算模型的准确率、召回率、F1-score等指标,评估模型的性能。性能优化包括调整超参数、增加数据量和模型集成等方法。

1.4.1 模型评估指标

常见的模型评估指标包括准确率(Accuracy)、精确率(Precision)、召回率(Recall)和F1-score等。

from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score# 计算评估指标
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred, average='weighted')
recall = recall_score(y_test, y_pred, average='weighted')
f1 = f1_score(y_test, y_pred, average='weighted')print(f'Accuracy: {accuracy}')
print(f'Precision: {precision}')
print(f'Recall: {recall}')
print(f'F1-score: {f1}')
1.4.2 超参数调优

通过网格搜索(Grid Search)和随机搜索(Random Search)等方法,对模型的超参数进行调优,找到最优的参数组合。

from sklearn.model_selection import GridSearchCV# 定义超参数网格
param_grid = {'C': [0.1, 1, 10],'gamma': [0.001, 0.01, 0.1],'kernel': ['linear', 'rbf']
}# 网格搜索
grid_search = GridSearchCV(estimator=SVC(), param_grid=param_grid, cv=5, scoring='accuracy')
grid_search.fit(X_train, y_train)# 输出最优参数
best_params = grid_search.best_params_
print(f'Best parameters: {best_params}')# 使用最优参数训练模型
model = SVC(**best_params)
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
1.4.3 增加数据量

通过数据增强和采样技术,增加训练数据量,提高模型的泛化能力和预测性能。

from imblearn.over_sampling import SMOTE# 数据增强
smote = SMOTE(random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train, y_train)# 训练模型
model.fit(X_resampled, y_resampled)# 预测与评估
y_pred = model.predict(X_test)
1.4.4 模型集成

通过模型集成的方法,将多个模型的预测结果进行组合,提高模型的稳定性和预测精度。常见的模型集成方法包括Bagging、Boosting和Stacking等。

from sklearn.ensemble import VotingClassifier# 构建模型集成
ensemble_model = VotingClassifier(estimators=[('nb', MultinomialNB()),('svm', SVC(kernel='linear', probability=True)),('rf', RandomForestClassifier())
], voting='soft')# 训练集成模型
ensemble_model.fit(X_train, y_train)# 预测与评估
y_pred = ensemble_model.predict(X_test)

在这里插入图片描述

第二章:自然语言处理的具体案例分析

2.1 情感分析

情感分析是通过分析文本内容,识别其中的情感倾向,广泛应用于社交媒体分析、市场调研和客户反馈等领域。以下是情感分析的具体案例分析。

2.1.1 数据预处理

首先,对情感分析数据集进行预处理,包括数据清洗、分词、去停用词和特征提取。

# 示例文本数据
texts = ["I love this product! It's amazing.","This is the worst experience I've ever had.","I'm very happy with the service.","The quality is terrible."
]
labels = [1, 0, 1, 0]  # 1表示正面情感,0表示负面情感# 数据清洗
cleaned_texts = [clean_text(text) for text in texts]# 分词
tokenized_texts = [word_tokenize(text) for text in cleaned_texts]# 去停用词
filtered_texts = [' '.join([word for word in tokens if word not in stop_words]) for tokens in tokenized_texts]# 特征提取
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(filtered_texts)
2.1.2 模型选择与训练

选择合适的模型进行训练,这里以朴素贝叶斯为例。

# 数据分割
X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2, random_state=42)# 训练朴素贝叶斯模型
model = MultinomialNB()
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
2.1.3 模型评估与优化

评估模型的性能,并进行超参数调优和数据增强。

# 评估模型
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)print(f'Accuracy: {accuracy}')
print(f'Precision: {precision}')
print(f'Recall: {recall}')
print(f'F1-score: {f1}')# 超参数调优
param_grid = {'alpha': [0.1, 0.5, 1.0]
}
grid_search = GridSearchCV(estimator=MultinomialNB(), param_grid=param_grid, cv=5, scoring='accuracy')
grid_search.fit(X_train, y_train)
best_params = grid_search.best_params_
print(f'Best parameters: {best_params}')# 使用最优参数训练模型
model = MultinomialNB(**best_params)
model.fit(X_train, y_train)# 数据增强
smote = SMOTE(random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train, y_train)
model.fit(X_resampled, y_resampled)# 预测与评估
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)print(f'Optimized Accuracy: {accuracy}')
print(f'Optimized Precision: {precision}')
print(f'Optimized Recall: {recall}')
print(f'Optimized F1-score: {f1}')

2.2 文本分类

文本分类是通过分析文本内容,将文本分配到预定义的类别中,广泛应用于新闻分类、垃圾邮件检测和主题识别等领域。以下是文本分类的具体案例分析。

2.2.1 数据预处理
# 示例文本数据
texts = ["The stock market is performing well today.","A new study shows the health benefits of coffee.","The local sports team won their game last night.","There is a new movie released this weekend."
]
labels = [0, 1, 2, 3]  # 示例标签,分别表示金融、健康、体育和娱乐# 数据清洗
cleaned_texts = [clean_text(text) for text in texts]# 分词
tokenized_texts = [word_tokenize(text) for text in cleaned_texts]# 去停用词
filtered_texts = [' '.join([word for word in tokens if word not in stop_words]) for tokens in tokenized_texts]# 特征提取
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(filtered_texts)
2.2.2 模型选择与训练

选择合适的模型进行训练,这里以支持向量机为例。

# 数据分割
X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2, random_state=42)# 训练支持向量机模型
model = SVC(kernel='linear')
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
2.2.3 模型评估与优化

评估模型的性能,并进行超参数调优和数据增强。

# 评估模型
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred, average='weighted')
recall = recall_score(y_test, y_pred, average='weighted')
f1 = f1_score(y_test, y_pred, average='weighted')print(f'Accuracy: {accuracy}')
print(f'Precision: {precision}')
print(f'Recall:{recall}')
print(f'F1-score: {f1}')# 超参数调优
param_grid = {'C': [0.1, 1, 10],'gamma': [0.001, 0.01, 0.1],'kernel': ['linear', 'rbf']
}
grid_search = GridSearchCV(estimator=SVC(), param_grid=param_grid, cv=5, scoring='accuracy')
grid_search.fit(X_train, y_train)
best_params = grid_search.best_params_
print(f'Best parameters: {best_params}')# 使用最优参数训练模型
model = SVC(**best_params)
model.fit(X_train, y_train)# 数据增强
smote = SMOTE(random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train, y_train)
model.fit(X_resampled, y_resampled)# 预测与评估
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred, average='weighted')
recall = recall_score(y_test, y_pred, average='weighted')
f1 = f1_score(y_test, y_pred, average='weighted')print(f'Optimized Accuracy: {accuracy}')
print(f'Optimized Precision: {precision}')
print(f'Optimized Recall: {recall}')
print(f'Optimized F1-score: {f1}')

2.3 机器翻译

机器翻译是通过分析和理解源语言文本,生成目标语言文本,广泛应用于跨语言交流和信息传播等领域。以下是机器翻译的具体案例分析。

2.3.1 数据预处理
# 示例文本数据
source_texts = ["Hello, how are you?","What is your name?","I love learning new languages.","Goodbye!"
]
target_texts = ["Hola, ¿cómo estás?","¿Cuál es tu nombre?","Me encanta aprender nuevos idiomas.","¡Adiós!"
]# 数据清洗
cleaned_source_texts = [clean_text(text) for text in source_texts]
cleaned_target_texts = [clean_text(text) for text in target_texts]# 分词
tokenized_source_texts = [word_tokenize(text) for text in cleaned_source_texts]
tokenized_target_texts = [word_tokenize(text) for text in cleaned_target_texts]# 创建词汇表
source_vocab = set(word for sentence in tokenized_source_texts for word in sentence)
target_vocab = set(word for sentence in tokenized_target_texts for word in sentence)# 词汇表到索引的映射
source_word_to_index = {word: i for i, word in enumerate(source_vocab)}
target_word_to_index = {word: i for i, word in enumerate(target_vocab)}# 将文本转换为索引
def text_to_index(text, word_to_index):return [word_to_index[word] for word in text if word in word_to_index]indexed_source_texts = [text_to_index(sentence, source_word_to_index) for sentence in tokenized_source_texts]
indexed_target_texts = [text_to_index(sentence, target_word_to_index) for sentence in tokenized_target_texts]
2.3.2 模型选择与训练

选择合适的模型进行训练,这里以LSTM为例。

from keras.models import Model
from keras.layers import Input, LSTM, Dense, Embedding# 定义编码器
encoder_inputs = Input(shape=(None,))
encoder_embedding = Embedding(len(source_vocab), 256)(encoder_inputs)
encoder_lstm = LSTM(256, return_state=True)
encoder_outputs, state_h, state_c = encoder_lstm(encoder_embedding)
encoder_states = [state_h, state_c]# 定义解码器
decoder_inputs = Input(shape=(None,))
decoder_embedding = Embedding(len(target_vocab), 256)(decoder_inputs)
decoder_lstm = LSTM(256, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_lstm(decoder_embedding, initial_state=encoder_states)
decoder_dense = Dense(len(target_vocab), activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)# 构建模型
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])# 数据准备
X_train_source = np.array(indexed_source_texts)
X_train_target = np.array(indexed_target_texts)# 训练模型
model.fit([X_train_source, X_train_target], y_train, epochs=10, batch_size=32, validation_split=0.2)
2.3.3 模型评估与优化

评估模型的性能,并进行超参数调优和数据增强。

# 评估模型
loss, accuracy = model.evaluate([X_test_source, X_test_target], y_test)
print(f'Accuracy: {accuracy}')# 超参数调优
param_grid = {'batch_size': [16, 32, 64],'epochs': [10, 20, 30]
}
grid_search = GridSearchCV(estimator=model, param_grid=param_grid, cv=5, scoring='accuracy')
grid_search.fit([X_train_source, X_train_target], y_train)
best_params = grid_search.best_params_
print(f'Best parameters: {best_params}')# 使用最优参数训练模型
model = model.set_params(**best_params)
model.fit([X_train_source, X_train_target], y_train, epochs=10, validation_data=([X_test_source, X_test_target], y_test))# 数据增强
smote = SMOTE(random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train_source, y_train)
model.fit([X_resampled, X_train_target], y_resampled)# 预测与评估
y_pred = model.predict([X_test_source, X_test_target])

在这里插入图片描述

第三章:性能优化与前沿研究

3.1 性能优化

3.1.1 特征工程

通过特征选择、特征提取和特征构造,优化模型的输入,提高模型的性能。

from sklearn.feature_selection import SelectKBest, f_classif# 特征选择
selector = SelectKBest(score_func=f_classif, k=10)
X_selected = selector.fit_transform(X, y)
3.1.2 超参数调优

通过网格搜索和随机搜索,找到模型的最优超参数组合。

from sklearn.model_selection import RandomizedSearchCV# 随机搜索
param_dist = {'n_estimators': [50, 100, 150],'max_depth': [3, 5, 7, 10],'min_samples_split': [2, 5, 10]
}
random_search = RandomizedSearchCV(estimator=RandomForestClassifier(), param_distributions=param_dist, n_iter=10, cv=5, scoring='accuracy')
random_search.fit(X_train, y_train)
best_params = random_search.best_params_
print(f'Best parameters: {best_params}')# 使用最优参数训练模型
model = RandomForestClassifier(**best_params)
model.fit(X_train, y_train)# 预测与评估
y_pred = model.predict(X_test)
3.1.3 模型集成

通过模型集成,提高模型的稳定性和预测精度。

from sklearn.ensemble import StackingClassifier# 构建模型集成
stacking_model = StackingClassifier(estimators=[('nb', MultinomialNB()),('svm', SVC(kernel='linear', probability=True)),('rf', RandomForestClassifier())
], final_estimator=LogisticRegression())# 训练集成模型
stacking_model.fit(X_train, y_train)# 预测与评估
y_pred = stacking_model.predict(X_test)

3.2 前沿研究

3.2.1 自监督学习在自然语言处理中的应用

自监督学习通过生成伪标签进行训练,提高模型的表现,特别适用于无监督数据的大规模训练。

3.2.2 增强学习在自然语言处理中的应用

增强学习通过与环境的交互,不断优化策略,在对话系统和问答系统中具有广泛的应用前景。

3.2.3 多模态学习与跨领域应用

多模态学习通过结合文本、图像和音频等多种模态,提高模型的理解能力,推动自然语言处理技术在跨领域中的应用。

结语

机器学习作为自然语言处理领域的重要技术,已经在多个应用场景中取得了显著的成果。通过对数据的深入挖掘和模型的不断优化,机器学习技术将在自然语言处理中发挥更大的作用,推动语言理解和生成技术的发展。

在这里插入图片描述

相关文章:

【机器学习】机器学习与自然语言处理的融合应用与性能优化新探索

引言 自然语言处理&#xff08;NLP&#xff09;是计算机科学中的一个重要领域&#xff0c;旨在通过计算机对人类语言进行理解、生成和分析。随着深度学习和大数据技术的发展&#xff0c;机器学习在自然语言处理中的应用越来越广泛&#xff0c;从文本分类、情感分析到机器翻译和…...

ubuntu优化

rootlocalhost:~# grep -E "^(PermitRootLogin|GSSAPIAuthentication|UseDNS)" /etc/ssh/sshd_config PermitRootLogin yes GSSAPIAuthentication no UseDNS norootlocalhost:~# systemctl restart sshd#此时就可以设置root密码了rootlocalhost:~# passwd New passw…...

使用 HBuilder X 进行 uniapp 小程序开发遇到的问题合集

文章目录 背景介绍问题集锦1. 在 HBuilderX 点击浏览器运行时&#xff0c;报 uni-app vue3编译器下载失败 安装错误2.在 HBuilderX 点击微信小程序运行时&#xff0c;报 微信开发者工具打开项目失败&#xff0c;请参阅启动日志错误 背景介绍 HBuilder X 版本&#xff1a;HBui…...

Python爬虫获取视频

验证电脑是否安装python 1.winr输入cmd 2.在黑窗口输入 python.exe 3.不是命令不存在就说明python环境安装完成 抓取快手视频 1.在phcharm应用中新建一个项目 3.新建一个python文件 4.选择python文件,随便起一个名字后按回车 5.安装requests pip install requests 6.寻找需要的…...

Python自动化,实现自动登录并爬取商品数据,实现数据可视化

关于如何使用Python自动化登录天 猫并爬取商品数据的指南&#xff0c;我们需要明确这是一个涉及多个步骤的复杂过程&#xff0c;且需要考虑到天猫的反爬虫策略。以下是一个简化的步骤指南&#xff1a; 步骤一&#xff1a;准备工作 环境准备&#xff1a;确保你的Python环境已经…...

计算机网络——数据链路层(以太网)

目录 局域网的数据链路层 局域网可按照网络拓扑分类 局域网与共享信道 以太网的两个主要标准 适配器与mac地址 适配器的组成与运作 MAC地址 MAC地址的详细介绍 局域网的mac地址格式 mac地址的发送顺序 单播、多播&#xff0c;广播mac地址 mac帧 如何取用…...

Java ORM框架FastMybatis踩坑

Java ORM框架FastmyBatis踩坑 问题&#xff1a;使用了FastmyBatis的saveOrUpdate方法&#xff0c;明明设置了主键的值且表中存在&#xff0c;但是依然执行insert操作。导致Duplicate PK。 原因&#xff1a;使用了其他第三方包的注解指定表的主键&#xff0c;没有按照FastmyBat…...

AI是在帮助开发者还是取代他们?

AI是在帮助开发者还是取代他们&#xff1f; 在软件开发领域&#xff0c;生成式人工智能&#xff08;AIGC&#xff09;正在改变开发者的工作方式。无论是代码生成、错误检测还是自动化测试&#xff0c;AI工具正在成为开发者的得力助手。然而&#xff0c;这也引发了对开发者职业…...

C. Theofanis‘ Nightmare

原题链接 : Problem - 1903C - Codeforces 思路 &#xff1a; 创建一个后缀和数组 &#xff0c; 然后把所有后缀和>0的加入到答案中&#xff0c;注意,整个数组的和一定要加入答案中 ; 代码 java : package sf;import java.util.Scanner; import java.util.* ;public …...

加密货币大利好!9月降息概率突破70%!美国可能大幅降息或多次降息?

根据最新消息&#xff0c;美国9月降息的概率已经突破70%&#xff0c;这对加密货币市场来说是个利好消息。与此同时&#xff0c;美国经济表现疲软&#xff0c;可能会陷入衰退&#xff0c;联邦储备系统(Fed)接下来会不会果断采取大幅降息措施备受关注。 美国劳工统计局7月5日公布…...

Dns被莫名篡改的逆向分析定位(笔记)

引言&#xff1a;最近发现用户的多台机器上出现了Dns被莫名修改的问题&#xff0c;从系统事件上看并未能正常确定到是那个具体软件所为&#xff0c;现在的需求就是确定和定位哪个软件具体所为。 解决思路&#xff1a; 首先到IPv4设置页面对Dns进行设置&#xff1a;通过ProcExp…...

SpringBoot中整合ONLYOFFICE在线编辑

SpringBoot整合OnlyOffice SpringBoot整合OnlyOffice实现在线编辑1. 搭建私有的OnlyOffice的服务2. SpringBoot进行交互2.1 环境2.2 我们的流程2.3 接口规划2.3.1 获取编辑器配置的接口2.3.2 文件下载地址2.3.3 文件下载地址 3. 总结4. 注意4.1 你的项目的地址一定一定要和only…...

Python打字练习

代码解析 导入模块和定义单词列表 import tkinter as tk import randomsample_words ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi", "lemon", "mango", &quo…...

Pytorch添加自定义算子之(10)-mmdeploy编译流程

整体参考 一、mmcv的编译安装 见上一篇 opencv的安装 $env:OpenCV_DIR = "D:\git_clone\opencv\build" # 我这里下载解压之后的地址 $env:path = "$env:OpenCV_DIR\x64\vc15\bin;" + $env:path $env:path = "D:\git_clone\opencv\build\OpenCVConf…...

大数据面试题之Flink(4)

Flink广播流 Flink实时topN 在实习中一般都怎么用Flink Savepoint知道是什么吗 为什么用Flink不用别的微批考虑过吗 解释一下啥叫背压 Flink分布式快照 Flink SQL解析过程 Flink on YARN模式 Flink如何保证数据不丢失 Flink广播流 Apache Flink 中的广播流&…...

C#实战|账号管理系统:通用登录窗体的实现。

哈喽,你好啊,我是雷工! 本节记录登录窗体的实现方法,比较有通用性,所有的项目登录窗体实现基本都是这个实现思路。 一通百通,以下为学习笔记。 01 登录窗体的逻辑 用户在登录窗输入账号和密码,如果输入账号和密码信息正确,点击【登录】按钮,则跳转显示主窗体,同时在固…...

php简单商城小程序系统源码

&#x1f6cd;️【简单商城小程序】&#x1f6cd;️ &#x1f680;一键开启&#xff0c;商城搭建新体验&#x1f680; 你还在为繁琐的商城搭建流程头疼吗&#xff1f;现在&#xff0c;有了简单商城系统小程序&#xff0c;一切变得轻松又快捷&#xff01;无需复杂的编程知识&a…...

NativeMemoryTracking查看java内存信息

默认该功能是禁用的&#xff0c;因为会损失5-10%的性能 开启命令 -XX:NativeMemoryTrackingdetail 打印命令 jcmd 45064 VM.native_memory summary scaleMB > NativeMemoryTracking.log 具体的日志信息 ➜ ~ ➜ ~ jcmd 45064 VM.native_memory summary scaleMB 45064…...

建智慧医院核心:智能导航系统的功能全析与实现效益

在数字化转型的浪潮中&#xff0c;智慧医院的建设是医疗行业数字化转型的关键步骤。随着医院规模的不断扩大和医疗设施的日益复杂&#xff0c;传统的静态不连续的导航方式已无法满足患者的需求。院内智能导航系统&#xff0c;作为医疗数字化转型的关键组成部分&#xff0c;正逐…...

数据库基础之:函数依赖

函数依赖在数据库设计中是非常关键的概念&#xff0c;用于描述关系数据库中数据项之间的相关性。下面我将通过几个例子来说明函数依赖的几种类型&#xff1a;完全函数依赖、部分函数依赖和传递函数依赖。 完全函数依赖 考虑一个关系模式 Student&#xff0c;包含属性 Student…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

CVPR 2025 MIMO: 支持视觉指代和像素grounding 的医学视觉语言模型

CVPR 2025 | MIMO&#xff1a;支持视觉指代和像素对齐的医学视觉语言模型 论文信息 标题&#xff1a;MIMO: A medical vision language model with visual referring multimodal input and pixel grounding multimodal output作者&#xff1a;Yanyuan Chen, Dexuan Xu, Yu Hu…...

【HarmonyOS 5 开发速记】如何获取用户信息(头像/昵称/手机号)

1.获取 authorizationCode&#xff1a; 2.利用 authorizationCode 获取 accessToken&#xff1a;文档中心 3.获取手机&#xff1a;文档中心 4.获取昵称头像&#xff1a;文档中心 首先创建 request 若要获取手机号&#xff0c;scope必填 phone&#xff0c;permissions 必填 …...

[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG

TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码&#xff1a;HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…...

Python常用模块:time、os、shutil与flask初探

一、Flask初探 & PyCharm终端配置 目的: 快速搭建小型Web服务器以提供数据。 工具: 第三方Web框架 Flask (需 pip install flask 安装)。 安装 Flask: 建议: 使用 PyCharm 内置的 Terminal (模拟命令行) 进行安装,避免频繁切换。 PyCharm Terminal 配置建议: 打开 Py…...

Android屏幕刷新率与FPS(Frames Per Second) 120hz

Android屏幕刷新率与FPS(Frames Per Second) 120hz 屏幕刷新率是屏幕每秒钟刷新显示内容的次数&#xff0c;单位是赫兹&#xff08;Hz&#xff09;。 60Hz 屏幕&#xff1a;每秒刷新 60 次&#xff0c;每次刷新间隔约 16.67ms 90Hz 屏幕&#xff1a;每秒刷新 90 次&#xff0c;…...

SQL进阶之旅 Day 22:批处理与游标优化

【SQL进阶之旅 Day 22】批处理与游标优化 文章简述&#xff08;300字左右&#xff09; 在数据库开发中&#xff0c;面对大量数据的处理任务时&#xff0c;单条SQL语句往往无法满足性能需求。本篇文章聚焦“批处理与游标优化”&#xff0c;深入探讨如何通过批量操作和游标技术提…...

当下AI智能硬件方案浅谈

背景&#xff1a; 现在大模型出来以后&#xff0c;打破了常规的机械式的对话&#xff0c;人机对话变得更聪明一点。 对话用到的技术主要是实时音视频&#xff0c;简称为RTC。下游硬件厂商一般都不会去自己开发音视频技术&#xff0c;开发自己的大模型。商用方案多见为字节、百…...

el-amap-bezier-curve运用及线弧度设置

文章目录 简介示例线弧度属性主要弧度相关属性其他相关样式属性完整示例链接简介 ‌el-amap-bezier-curve 是 Vue-Amap 组件库中的一个组件,用于在 高德地图 上绘制贝塞尔曲线。‌ 基本用法属性path定义曲线的路径,可以是多个弧线段的组合。stroke-weight线条的宽度。stroke…...

Linux中INADDR_ANY详解

在Linux网络编程中&#xff0c;INADDR_ANY 是一个特殊的IPv4地址常量&#xff08;定义在 <netinet/in.h> 头文件中&#xff09;&#xff0c;用于表示绑定到所有可用网络接口的地址。它是服务器程序中的常见用法&#xff0c;允许套接字监听所有本地IP地址上的连接请求。 关…...