SVM 就是一个分类器,它想在两个类别之间画一条“最宽的分界线”,让两边的数据离这条线越远越好。
你可以把它想象成:
在猫和狗之间划出一条“安全距离线”,谁靠得近谁就容易被误判。SVM 想让这条线尽可能远离两边的样本。
本教程通过Python代码实现核心公式+动态图演示,帮助你直观理解这些变换的本质。
将信号分解为不同频率的正弦波分量,揭示信号的频率组成。
Automatic Prefix Caching
https://docs.vllm.ai/en/latest/features/automatic_prefix_caching.html
如果每次query都有相同的前缀,那么启用这个参数将获得极大的推理时间收益:
bash展开代码enable_prefix_caching=True
查看当前word多少个表格:
vba展开代码Sub CountTablesInDocument() Dim tableCount As Long ' 获取文档中所有表格的数量 tableCount = ActiveDocument.Tables.Count ' 显示结果 If tableCount > 0 Then MsgBox "当前文档中包含 " & tableCount & " 个表格。", vbInformation, "表格统计" Else MsgBox "当前文档中没有表格。", vbInformation, "表格统计" End If End Sub
以下是强化学习中所有关键专有名词的统一解释,结合理论定义与直观理解,便于快速查阅。
给定维度 和位置 ,定义频率参数:
其中:
(1)梯度消失是深度神经网络训练过程中出现的一种现象,指的是在反向传播时,靠近输入层的梯度变得非常小,几乎趋近于零。这通常发生在使用如 Sigmoid 或 Tanh 等饱和激活函数的深层网络中,由于链式法则导致多个小于1的数连乘,使得梯度指数级衰减。
(2)梯度消失的现象主要表现为模型训练缓慢甚至停滞,靠近输入层的参数几乎不更新,导致网络无法有效学习特征。这会直接影响模型的收敛速度和最终性能,尤其在层数较多的情况下更为明显。
(3)缓解梯度消失的方法包括:使用如 ReLU 及其变体等非饱和激活函数;采用合适的参数初始化方法如 He 初始化 或 Xavier 初始化,保证信号传播的稳定性;引入 Batch Normalization 层来标准化每层输出;利用 残差连接(Residual Connection) 使梯度更容易回传;以及在必要时使用 梯度裁剪(Gradient Clipping) 防止梯度过小或过大带来的训练不稳定问题。
在当前Word按Alt+F11,然后输入代码:
vba展开代码Sub CheckIfDocumentHasPictures() Dim hasPictures As Boolean hasPictures = False ' 检查内联图片(InlineShapes) If ActiveDocument.InlineShapes.Count > 0 Then hasPictures = True End If ' 检查浮动图片(Shapes) If Not hasPictures Then If ActiveDocument.Shapes.Count > 0 Then hasPictures = True End If End If ' 显示结果 If hasPictures Then MsgBox "当前文档包含图片!", vbInformation, "检测结果" Else MsgBox "当前文档没有图片。", vbInformation, "检测结果" End If End Sub
py展开代码import numpy as np
import random
class KMeans:
def __init__(self, n_clusters=3, max_iter=300, tol=1e-4):
self.n_clusters = n_clusters # 聚类数量
self.max_iter = max_iter # 最大迭代次数
self.tol = tol # 收敛阈值
self.centroids = None # 聚类中心
self.labels = None # 样本标签
def fit(self, X):
# 1. 随机初始化聚类中心
n_samples = X.shape[0]
random_indices = random.sample(range(n_samples), self.n_clusters)
self.centroids = X[random_indices]
for _ in range(self.max_iter):
# 2. 分配样本到最近的聚类中心
distances = self._compute_distances(X)
self.labels = np.argmin(distances, axis=1)
# 3. 保存旧中心用于收敛判断
old_centroids = self.centroids.copy()
# 4. 更新聚类中心
for i in range(self.n_clusters):
# 获取属于当前聚类的所有样本
cluster_samples = X[self.labels == i]
if len(cluster_samples) > 0:
self.centroids[i] = np.mean(cluster_samples, axis=0)
# 5. 检查是否收敛
centroid_shift = np.linalg.norm(old_centroids - self.centroids)
if centroid_shift < self.tol:
break
def predict(self, X):
distances = self._compute_distances(X)
return np.argmin(distances, axis=1)
def _compute_distances(self, X):
# 计算每个样本到所有聚类中心的距离
distances = np.zeros((X.shape[0], self.n_clusters))
for i, centroid in enumerate(self.centroids):
distances[:, i] = np.linalg.norm(X - centroid, axis=1)
return distances
# 生成测试数据
np.random.seed(42)
X = np.vstack([
np.random.normal(loc=[0, 0], scale=1, size=(100, 2)),
np.random.normal(loc=[5, 5], scale=1, size=(100, 2)),
np.random.normal(loc=[-5, 5], scale=1, size=(100, 2))
])
# 训练K-Means
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)
# 预测
labels = kmeans.predict(X)
print("聚类中心:\n", kmeans.centroids)
多头:
py展开代码import torch
import torch.nn as nn
import torch.nn.functional as F
class SelfAttention(nn.Module):
def __init__(self, embed_size, heads):
super(SelfAttention, self).__init__()
self.embed_size = embed_size
self.heads = heads
self.head_dim = embed_size // heads
assert self.head_dim * heads == embed_size, "Embed size needs to be divisible by heads"
# 线性变换得到 Q, K, V
self.values = nn.Linear(embed_size, embed_size)
self.keys = nn.Linear(embed_size, embed_size)
self.queries = nn.Linear(embed_size, embed_size)
# 输出线性层
self.fc_out = nn.Linear(embed_size, embed_size)
def forward(self, x):
# x shape: (N, seq_len, embed_size)
N = x.shape[0]
seq_len = x.shape[1]
# 线性变换得到 Q, K, V
values = self.values(x) # (N, seq_len, embed_size)
keys = self.keys(x) # (N, seq_len, embed_size)
queries = self.queries(x) # (N, seq_len, embed_size)
# 分割多头
values = values.reshape(N, seq_len, self.heads, self.head_dim)
keys = keys.reshape(N, seq_len, self.heads, self.head_dim)
queries = queries.reshape(N, seq_len, self.heads, self.head_dim)
# 计算注意力分数
energy = torch.einsum("nqhd,nkhd->nhqk", [queries, keys])
# queries shape: (N, seq_len, heads, head_dim)
# keys shape: (N, seq_len, heads, head_dim)
# energy shape: (N, heads, seq_len, seq_len)
# 缩放点积注意力
attention = F.softmax(energy / (self.embed_size ** (1/2)), dim=3)
# 应用注意力到values上
out = torch.einsum("nhql,nlhd->nqhd", [attention, values])
# attention shape: (N, heads, seq_len, seq_len)
# values shape: (N, seq_len, heads, head_dim)
# out shape: (N, seq_len, heads, head_dim)
# 合并多头
out = out.reshape(N, seq_len, self.embed_size)
# 输出线性变换
out = self.fc_out(out)
return out
https://leetcode.cn/problems/add-two-numbers
给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。
请你将两个数相加,并以相同形式返回一个表示和的链表。
你可以假设除了数字 0 之外,这两个数都不会以 0 开头。
输入:l1 = [2,4,3], l2 = [5,6,4]
输出:[7,0,8]
解释:342 + 465 = 807.
python展开代码# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(
self, l1: Optional[ListNode], l2: Optional[ListNode]
) -> Optional[ListNode]:
dammy = ListNode() # 虚拟节点,最终返回这个节点的下一个节点
… head.next = ListNode(
v_dig
) # 第一轮 比如7+6=13,那么这里就是3。第二轮,2+5+1=8,链表会是 dammy>>3>>8,从个位开始的
head = head.next
if l1:
l1 = l1.next
if l2:
l2 = l2.next
return dammy.next
【训练】Qwen2.5VL 多机多卡 Grounding Box定位(1):http://101.126.150.28:7878/post/2067
【训练】Qwen2.5VL 多机多卡 Grounding Box定位(2):http://101.126.150.28:7878/post/2094
类似这样:
json展开代码 {
"messages": [
{
"content": "<image>点[56,259]所处位置(也即是图中绿色五角星中心所处位置)的信息是什么?需要优先匹配最近UI元素的box。",
"role": "user"
},
{
"content": "<ref>文本-地址</ref><box>[[33, 241, 66, 264]]</box>",
"role": "assistant"
}
],
"images": [
"/img_datasets/img_small_size_28_prompt/000001.jpg"
]
}
自注意力机制(Self-Attention) 是Transformer中最耗时的部分。
在没有额外显卡的情况下,当你遇到训练模型时出现"out of memory"错误,可以尝试以下几种解决方案: