CS224N第二课作业--word2vec与skipgram

news2024/10/7 12:24:06

文章目录

CS224N: 作业2 word2vec (49 Points)

1. Math: 理解 word2vec

word2vec 的关键思想是: a word is known by the company it keeps.
给定一个中心词 c c c, 一个大小为 n n n 的窗口, 那么相对于 c c c 的上下文就是 O O O, 例如在文本: ... problems turning into banking crises as ... 中, 若 c c cbanking, n = 2 n=2 n=2, 则 O O Oturning into crises as 这4个单词.

因此, Skip-gram word2vec 的目的就是学习一个概率分布: P ( O ∣ C ) P(O|C) P(OC). 特别的, 对于一个特定的中心词 c c c 和一个特定的上下文单词 o o o, 我们有: P ( O = o ∣ C = c ) = exp ⁡ ( u o T v c ) Σ w ∈ V o c a b exp ⁡ ( u w T v c ) P(O=o|C=c)=\frac{\exp{(u_o^Tv_c)}}{\Sigma_{w\in Vocab}\exp{(u_w^Tv_c)}} P(O=oC=c)=ΣwVocabexp(uwTvc)exp(uoTvc)

这里, Vocab 是指词汇表, 它的长度为 N. 定义两个矩阵 UV, U 表示 outside word vectors, 大小为 (D, N), 也即该矩阵的列向量 U i U_i Ui 表示词表第 i 个单词的词向量, 词向量维数是 D. V 矩阵大小与 U 相同, 但他表示每个单词作为中心词时的词向量矩阵.

接下来根据优化目标来定义损失函数.
对于特定的 c c c o o o, 它的损失贡献是:
J n a i v e − s o f t m a x ( v c , o , U ) = − log ⁡ P ( O = o ∣ C = c ) J_{naive-softmax}(v_c, o, U) = −\log{P(O = o|C = c)} Jnaivesoftmax(vc,o,U)=logP(O=oC=c)

这可以视为 真实分布 y y y预测分布 y ^ \hat{y} y^ 之间的交叉熵损失(对于特定的 c c c o o o), 这里 y y y y ^ \hat{y} y^为N维向量, 第 k 个分量表示词汇表第k个词是指定中心词 c c coutside word 的条件概率. y y y 是一个 one-hot 向量, 它在实际 outside word 的分量处为1, 其它地方是0. y ^ \hat{y} y^ P ( O ∣ C = c ) P(O|C=c) P(OC=c) 给出. 因此很容易就能看出该损失函数实际上就是真实分布 y y y预测分布 y ^ \hat{y} y^ 之间的交叉熵损失

插播一条定义, 交叉熵的定义是:

  • Cross-Entropy Loss
    The cross-entropy loss between the true (discrete) probability distribution p p p and another distribution q q q is: − Σ i p i l o g ( q i ) -\Sigma_{i}p_ilog(q_i) Σipilog(qi)

计算 J n a i v e − s o f t m a x ( v c , o , U ) J_{naive-softmax}(v_c, o, U) Jnaivesoftmax(vc,o,U) 关于 v c v_c vc 的偏导数

结果只能使用 y y y y ^ \hat{y} y^ 以及 U U U 来表示, 请给出详细计算过程
∂ ( J ) ∂ ( v c ) = ∂ ∂ ( v c ) ( − log ⁡ P ( O = o ∣ C = c ) ) = ∂ ∂ ( v c ) ( log ⁡ ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) − u o T v c ) = − u o + 1 ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) ∂ ∂ ( v c ) ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) = − u o + ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) u w ∑ u x ∈ V o c a b ( exp ⁡ u x T v c ) = − u o + ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) ∑ u x ∈ V o c a b ( exp ⁡ u x T v c ) u w = − u o + ∑ u w ∈ V o c a b P ( O = w ∣ C = c ) u w = − u o + ∑ u w ∈ V o c a b y w ^ u w = − u o + U y ^ = U ( y ^ − y ) \begin{align*} \frac{\partial(J)}{\partial(v_c)} & = \frac{\partial}{\partial(v_c)}{(−\log P(O = o|C = c))} \\ & =\frac{\partial}{\partial(v_c)}(\log \sum_{u_w\in Vocab}(\exp{u_w^Tv_c})-u_o^Tv_c) \\ & = -u_o + \frac{1}{\sum_{u_w\in Vocab}(\exp{u_w^Tv_c})}\frac{\partial}{\partial(v_c)}\sum_{u_w\in Vocab}(\exp{u_w^Tv_c}) \\ & = -u_o + \frac{\sum_{u_w\in Vocab}(\exp{u_w^Tv_c})u_w}{\sum_{u_x\in Vocab}(\exp{u_x^Tv_c})} \\ & = -u_o + \sum_{u_w\in Vocab}\frac{(\exp{u_w^Tv_c})}{\sum_{u_x\in Vocab}(\exp{u_x^Tv_c})}u_w \\ & = -u_o + \sum_{u_w\in Vocab}P(O=w|C=c)u_w \\ & = -u_o + \sum_{u_w\in Vocab}\hat{y_w}u_w \\ & = -u_o + U\hat{y} = U(\hat{y}-y) \end{align*} (vc)(J)=(vc)(logP(O=oC=c))=(vc)(loguwVocab(expuwTvc)uoTvc)=uo+uwVocab(expuwTvc)1(vc)uwVocab(expuwTvc)=uo+uxVocab(expuxTvc)uwVocab(expuwTvc)uw=uo+uwVocabuxVocab(expuxTvc)(expuwTvc)uw=uo+uwVocabP(O=wC=c)uw=uo+uwVocabyw^uw=uo+Uy^=U(y^y)

  • When is the gradient you computed equal to zero?
    也即 $ U(\hat{y}-y)=0 $, 这是齐次线性方程组, 矩阵的行秩小于列秩, 此时方程组有无数解.

  • 计算得到的结果表现形式是一个差值的形式, 给出解释为什么当 v c v_c vc 减去这个偏导数后会提升 v c v_c vc 的表现.

计算 J n a i v e − s o f t m a x ( v c , o , U ) J_{naive-softmax}(v_c, o, U) Jnaivesoftmax(vc,o,U) 关于每一个 u w u_w uw 的偏导数

对上下文词向量 u w u_w uw求导
∂ ( J ) ∂ ( u w ) = ∂ ∂ ( u w ) ( − log ⁡ P ( O = o ∣ C = c ) ) = ∂ ∂ ( u w ) log ⁡ ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) − ∂ ∂ ( u w ) u o T v c \begin{align*} \frac{\partial(J)}{\partial(u_w)} &= \frac{\partial}{\partial(u_w)}{(−\log P(O = o|C = c))} \\ &= \frac{\partial}{\partial(u_w)}\log \sum_{u_w\in Vocab}(\exp{u_w^Tv_c})-\frac{\partial}{\partial(u_w)}u_o^Tv_c \end{align*} (uw)(J)=(uw)(logP(O=oC=c))=(uw)loguwVocab(expuwTvc)(uw)uoTvc
分为两部分计算, 对于前一部分 PartA:
p a r t A = exp ⁡ u w T v c ∑ u w ∈ V o c a b ( exp ⁡ u w T v c ) v c = P ( O = w ∣ C = c ) v c = y w ^ v c \begin{matrix} partA &=& \frac{\exp{u_w^Tv_c}}{\sum_{u_w\in Vocab}(\exp{u_w^Tv_c})}v_c=P(O=w|C=c)v_c=\hat{y_w}v_c \end{matrix} partA=uwVocab(expuwTvc)expuwTvcvc=P(O=wC=c)vc=yw^vc
对于后一个部分, 当 w 不等于 o 时, partB=0, 否则等于 v c v_c vc, 因此:
∂ ( J ) ∂ ( u w ) = ( y ^ w − y w ) v c \frac{\partial(J)}{\partial(u_w)}=(\hat{y}_w-y_w)v_c (uw)(J)=(y^wyw)vc

  • 计算 J n a i v e − s o f t m a x ( v c , o , U ) J_{naive-softmax}(v_c, o, U) Jnaivesoftmax(vc,o,U) 关于 U U U 的偏导数(也即把上面的结果表示为矩阵形式)
    ∂ ( J ) ∂ ( U ) = ⟨ ∂ ∂ ( u 1 ) , ∂ ∂ ( u 2 ) , … , ∂ ∂ ( u N ) ⟩ \begin{matrix} \frac{\partial(J)}{\partial(U)} & = \braket{\frac{\partial}{\partial(u_1)}, \frac{\partial}{\partial(u_2)}, \dots, \frac{\partial}{\partial(u_N)}} \end{matrix} (U)(J)=(u1),(u2),,(uN)

计算 The Leaky ReLU (Leaky Rectified Linear Unit) 的导函数

f ( x ) = max ⁡ ( α x , x ) ( 0 < α < 1 ) f(x) = \max(\alpha x, x) (0<\alpha<1) f(x)=max(αx,x)(0<α<1)
d d x f ( x ) = { α , x < = 0 1 , x > 0 \frac{d}{dx}f(x)= \begin{cases} \alpha, &x<=0 \\ 1, &x>0 \end{cases} dxdf(x)={α,1,x<=0x>0

计算 sigmoid function 的导函数

σ ( x ) = 1 1 + e − x \sigma(x) = \frac{1}{1+e^{-x}} σ(x)=1+ex1
σ ′ ( x ) = − 1 ( 1 + e − x ) 2 ∗ ( − e − x ) = e − x ( 1 + e − x ) 2 = σ ( x ) ( 1 − σ ( x ) ) \sigma'(x) = -\frac{1}{(1+e^{-x})^2}*(-e^{-x})=\frac{e^{-x}}{(1+e^{-x})^2}=\sigma(x)(1-\sigma(x)) σ(x)=(1+ex)21(ex)=(1+ex)2ex=σ(x)(1σ(x))

The Negative Sampling loss

考虑负采样的损失函数, 它是原生 softmax 损失的替代版, 假设先从词表中随机挑选 N 个负样本(单词), 标记为 w 1 , w 2 , … , w K w_1, w_2, \dots, w_K w1,w2,,wK, 它们的 outside vectors 是: u 1 , u 1 , … , u K u_1, u_1, \dots, u_K u1,u1,,uK. 注意, K个负样本互不相同, 上下文单词 o 不在这K个样本中. 那么对于指定的中心词c和外部词o, 损失函数是:
J n e g − s a m p l e ( v c , o , U ) = − log ⁡ ( σ ( u o T v c ) ) − ∑ s = 1 K log ⁡ ( σ ( − u s T v c ) ) J_{neg-sample(v_c, o, U)} = -\log(\sigma(u_o^Tv_c))-\sum_{s=1}^K \log{(\sigma(-u_s^Tv_c))} Jnegsample(vc,o,U)=log(σ(uoTvc))s=1Klog(σ(usTvc))

  • 计算 J 关于 v c v_c vc, u s u_s us 的偏导. 结果使用 v c v_c vc, u o u_o uo, u w s u_{w_s} uws来表达.
  • 依据链式求导法则, 反向传播算法在计算偏导时可以利用先前的计算以节省时间开销, 请结合偏导计算过程给出说明. 注意, 你可以使用如下符号: U o , { w 1 , … , w K } = [ u o , − u 1 , … , − u K ] U_{o,{\{w_1, \dots, w_K\}}}=[u_o, -u_1,\dots,-u_K] Uo,{w1,,wK}=[uo,u1,,uK] 和向量 1 \bf{1} 1(包含K+1个1).
  • 请用一句话说明为什么负采样损失要比原来的softmax损失更高效.

∂ ( J ) ∂ ( v c ) = ∂ ∂ ( v c ) ( − log ⁡ ( σ ( u o T v c ) ) ) + ∂ ( J ) ∂ ( v c ) ( − ∑ s = 1 K log ⁡ ( σ ( − u s T v c ) ) ) = A + B \begin{align*} \frac{\partial(J)}{\partial(v_c)} &= \frac{\partial}{\partial(v_c)}(-\log(\sigma(u_o^Tv_c))) + \frac{\partial(J)}{\partial(v_c)}(-\sum_{s=1}^K{\log(\sigma(-u_s^Tv_c))}) \\ &=A+B \end{align*} (vc)(J)=(vc)(log(σ(uoTvc)))+(vc)(J)(s=1Klog(σ(usTvc)))=A+B
计算 A:
A = − 1 σ ( u o T v c ) ∗ ( 1 − σ ( u o T v c ) ) σ ( u o T v c ) ∗ u o = ( σ ( u o T v c ) − 1 ) u o \begin{align*} A&=\frac{-1}{\sigma(u_o^Tv_c)}*(1-\sigma(u_o^Tv_c))\sigma(u_o^Tv_c)*u_o \\ &=(\sigma(u_o^Tv_c)-1)u_o \end{align*} A=σ(uoTvc)1(1σ(uoTvc))σ(uoTvc)uo=(σ(uoTvc)1)uo
计算 B:
B = ∑ s = 1 K − 1 σ ( − u s T v c ) ∗ σ ( − u s T v c ) ( 1 − σ ( − u s T v c ) ) ∗ ( − u s ) = ∑ s = 1 K ( 1 − σ ( − u s T v c ) ) u s \begin{align*} B&=\sum_{s=1}^K\frac{-1}{\sigma(-u_s^Tv_c)}*{\sigma(-u_s^Tv_c)}(1-\sigma(-u_s^Tv_c))*(-u_s)\\ &=\sum_{s=1}^K(1-\sigma(-u_s^Tv_c))u_s \end{align*} B=s=1Kσ(usTvc)1σ(usTvc)(1σ(usTvc))(us)=s=1K(1σ(usTvc))us
因此:
∂ ( J ) ∂ ( v c ) = ( σ ( u o T v c ) − 1 ) u o + ∑ s = 1 K ( 1 − σ ( − u s T v c ) ) u s \begin{align*} \frac{\partial(J)}{\partial(v_c)} &=(\sigma(u_o^Tv_c)-1)u_o+\sum_{s=1}^K(1-\sigma(-u_s^Tv_c))u_s \end{align*} (vc)(J)=(σ(uoTvc)1)uo+s=1K(1σ(usTvc))us
计算 J 关于 u s u_s us 的偏导数:
∂ ( J ) ∂ ( u s ) = ∂ ∂ ( u s ) ( − log ⁡ ( σ ( u o T v c ) ) ) + ∂ ( J ) ∂ ( u s ) ( − ∑ k = 1 K log ⁡ ( σ ( − u k T v c ) ) ) = − 1 σ ( − u s T v c ) ∗ σ ( − u s T v c ) ( 1 − σ ( − u s T v c ) ) ∗ ( − v c ) = ( 1 − σ ( − u s T v c ) ) v c \begin{align*} \frac{\partial(J)}{\partial(u_s)} &= \frac{\partial}{\partial(u_s)}(-\log(\sigma(u_o^Tv_c))) + \frac{\partial(J)}{\partial(u_s)}(-\sum_{k=1}^K{\log(\sigma(-u_k^Tv_c))}) \\ &= \frac{-1}{\sigma(-u_s^Tv_c)}*{\sigma(-u_s^Tv_c)}(1-\sigma(-u_s^Tv_c))*(-v_c) \\ &= (1-\sigma(-u_s^Tv_c))v_c \end{align*} (us)(J)=(us)(log(σ(uoTvc)))+(us)(J)(k=1Klog(σ(ukTvc)))=σ(usTvc)1σ(usTvc)(1σ(usTvc))(vc)=(1σ(usTvc))vc
计算 J 关于 u o u_o uo 的偏导数:
∂ ( J ) ∂ ( u o ) = ∂ ∂ ( u o ) ( − log ⁡ ( σ ( u o T v c ) ) ) = ( σ ( u o T v c ) − 1 ) v c \begin{align*} \frac{\partial(J)}{\partial(u_o)} &= \frac{\partial}{\partial(u_o)}(-\log(\sigma(u_o^Tv_c))) \\ &= (\sigma(u_o^Tv_c)-1)v_c \end{align*} (uo)(J)=(uo)(log(σ(uoTvc)))=(σ(uoTvc)1)vc

  • 负采样loss在计算导数时不需要遍历整个词表, 只需要K个负样本.

2. Code: 实现 word2vec

在这一部分,将实现word2vec模型,并使用随机梯度下降( SGD )训练自己的词向量。在开始之前,首先在任务目录内运行以下命令,以便创建合适的conda虚拟环境。这就保证了你有完成任务所必需的所有包。还需要注意的是,您可能希望在编写代码之前完成前面的数学部分,因为您将被要求在Python中实现数学函数。你可能会想按顺序实施和测试这一部分的每一部分,因为问题是循序渐进的。
对于每个需要实现的方法,我们在代码注释中包含了我们的解决方案大约有多少行代码。这些数字都包含在里面,用来指导你。你不必拘泥于它们,你可以随心所欲地编写更短或更长的代码。如果你认为你的实现比我们的实现长得多,那就表明你可以使用一些numpy方法来使你的代码既短又快。因为Python中的循环在使用大型数组时需要很长的时间才能完成,所以我们期望你使用numpy方法。我们将检查您的代码的效率。当你向Gradescope提交代码时,你就能看到自动评分器的结果,我们建议尽快提交代码。

(1). 我们将从 word2vec.py 入手开始实现方法。可以通过运行 python word2vec.py m 来测试特定的方法,其中m是您想要测试的方法。例如,可以通过运行python word2vec.py sigmoid来测试sigmoid方法。

a. Implement the sigmoid method, which takes in a vector and applies the sigmoid function to it.
b. Implement the softmax loss and gradient in the naiveSoftmaxLossAndGradient method.
c. Implement the negative sampling loss and gradient in the negSamplingLossAndGradient method.
d. Implement the skip-gram model in the skipgram method

When you are done, test your entire implementation by running python word2vec.py

(2). Complete the implementation for your SGD optimizer in the sgd method of sgd.py. Test your implementation by running python sgd.py

(3). 展示时间!现在我们要加载一些真实的数据,用你刚实现的一切来训练词向量!我们将使用Stanford Sentiment树库( SST )数据集来训练词向量,并将其应用到一个简单的情感分析任务中。首先需要获取数据集,为此,运行sh get dataset.sh。对于该部分没有额外编写的代码;只需运行 python run.py. 经过40,000次迭代后,脚本将完成,并出现一个词向量的可视化。也会以 word_vectors.png 的形式保存在项目目录中。将结果图片包含在你的作业中写出来。至多用三句话简要解释一下你在结果图片中看到的内容。这可能包括但不限于对聚类的观察和你希望聚类但没有聚类的单词。
以下贴出核心实现:

def naiveSoftmaxLossAndGradient(centerWordVec, outsideWordIdx, outsideVectors, datase):
	### YOUR CODE HERE (~6-8 Lines)
    y_hat = softmax(np.matmul(outsideVectors, centerWordVec))   # y_hat = P(O|C=c), (N,)
    y = np.zeros(y_hat.shape[0])
    y[outsideWordIdx] = 1                                       # y, one-hot vector, (N,)
    loss = -np.log(y_hat[outsideWordIdx])                       # loss = -log(y_hat[o]), scalar
    gradCenterVec = np.matmul(outsideVectors.T, y_hat-y)        # dJ/dv_c = U(y_hat-y), (D,)
    gradOutsideVecs = np.matmul((y_hat-y).reshape(-1,1), centerWordVec.reshape(1,-1))   # (N, D)
    ### END YOUR CODE
    return loss, gradCenterVec, gradOutsideVecs

def negSamplingLossAndGradient(centerWordVec, outsideWordIdx, outsideVectors, dataset, K=10):
    # Negative sampling of words is done for you. Do not modify this if you
    # wish to match the autograder and receive points!
    negSampleWordIndices = getNegativeSamples(outsideWordIdx, dataset, K)
    indices = [outsideWordIdx] + negSampleWordIndices

    ### YOUR CODE HERE (~10 Lines)
    gradCenterVec = np.zeros_like(centerWordVec)
    gradOutsideVecs = np.zeros_like(outsideVectors)
    # loss function
    loss = -np.log(sigmoid(outsideVectors[outsideWordIdx].dot(centerWordVec)))
    for idx in negSampleWordIndices:
        loss -= np.log(sigmoid(-outsideVectors[idx].dot(centerWordVec)))
    # gradient
    gradCenterVec -= (1 - sigmoid(centerWordVec.dot(outsideVectors[outsideWordIdx]))) * outsideVectors[outsideWordIdx]
    for k in negSampleWordIndices:
        gradCenterVec += (1 - sigmoid(-centerWordVec.dot(outsideVectors[k]))) * outsideVectors[k]
    gradOutsideVecs[outsideWordIdx] = -(1 - sigmoid(centerWordVec.dot(outsideVectors[outsideWordIdx]))) * centerWordVec
    for k in negSampleWordIndices:
        gradOutsideVecs[k] += (1 - sigmoid(-centerWordVec.dot(outsideVectors[k]))) * centerWordVec
    ### END YOUR CODE
    return loss, gradCenterVec, gradOutsideVecs

def skipgram(currentCenterWord, windowSize, outsideWords, word2Ind,
             centerWordVectors, outsideVectors, dataset,
             word2vecLossAndGradient=naiveSoftmaxLossAndGradient):
	loss = 0.0
    gradCenterVecs = np.zeros(centerWordVectors.shape)
    gradOutsideVectors = np.zeros(outsideVectors.shape)
    ### YOUR CODE HERE (~8 Lines)
    currentCenterIdx = word2Ind[currentCenterWord]
    for word in outsideWords:
        loss_w, grad_cv, grad_ov = word2vecLossAndGradient(
            centerWordVectors[currentCenterIdx],
            word2Ind[word],
            outsideVectors,
            dataset
        )
        loss += loss_w
        gradCenterVecs[currentCenterIdx] += grad_cv
        gradOutsideVectors += grad_ov
    ### END YOUR CODE
    return loss, gradCenterVecs, gradOutsideVectors

sgd部分:

### YOUR CODE HERE (~2 lines)
loss, grad = f(x)
x = x - step*grad
### END YOUR CODE

运行结果:

iter 39910: 9.324637
iter 39920: 9.284225
iter 39930: 9.298478
iter 39940: 9.296606
iter 39950: 9.313374
iter 39960: 9.317475
iter 39970: 9.330720
iter 39980: 9.410215
iter 39990: 9.418270
iter 40000: 9.367644
sanity check: cost at convergence should be around or below 10
training took 6372 seconds

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1589690.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

QAT量化 demo

一、QAT量化基本流程 QAT过程可以分解为以下步骤&#xff1a; 定义模型&#xff1a;定义一个浮点模型&#xff0c;就像常规模型一样。定义量化模型&#xff1a;定义一个与原始模型结构相同但增加了量化操作&#xff08;如torch.quantization.QuantStub()&#xff09;和反量化…

Vue3+Ant Design表格排序

最近在公司做有关报表的项目时&#xff0c;遇到最多的问题-表格排序&#xff0c;刚开始看到UI设计图的时候&#xff0c;还有些纳闷这个排序如何做&#xff0c;其实实际上并没有想象中的那么难&#xff0c;如果说单纯的排序的话ant design这个组件里的表格有自带的排序和筛选功能…

知名专业定制线缆源头工厂推荐-精工电联:智能制造线缆的前沿技术探索

优质定制线缆源头厂家推荐-精工电联&#xff1a;智能制造线缆的前沿技术探索 知名专业定制线缆源头工厂推荐-精工电联&#xff1a;智能制造线缆的前沿技 在科技飞速发展的当今时代&#xff0c;智能制造已成为工业4.0的核心驱动力。精工电联&#xff0c;作为智能制造领先的高品质…

基于Python的LSTM网络实现单特征预测回归任务(pytorch版)

一、数据集 自建数据集--【load.xlsx】。包含2列&#xff1a; date列&#xff08;时间列&#xff0c;记录2022年6月2日起始至2023年12月31日为止&#xff0c;日度数据&#xff09;price列&#xff08;价格列&#xff0c;记录日度数据对应的某品牌衣服的价格&#xff0c;浮点数…

【LAMMPS学习】八、基础知识(2.2)类型标签

8. 基础知识 此部分描述了如何使用 LAMMPS 为用户和开发人员执行各种任务。术语表页面还列出了 MD 术语&#xff0c;以及相应 LAMMPS 手册页的链接。 LAMMPS 源代码分发的 examples 目录中包含的示例输入脚本以及示例脚本页面上突出显示的示例输入脚本还展示了如何设置和运行各…

请核对您的姓名、证件号码、有效期和年限是否选择正确,请勿使用挂失过的身份证

问题 请核对您的姓名、证件号码、有效期和年限是否选择正确&#xff0c;请勿使用挂失过的身份证 详细问题 笔者在专利业务办理系统进行新用户注册&#xff0c;注册时间为晚上大概22&#xff1a;00以后。注册时已核对姓名、证件号码、有效期和年限&#xff0c;已确保正确&…

【C++】拆分详解 - 内存管理

文章目录 前言一、C/C内存分布二、C语言中动态内存管理方式&#xff1a;malloc/calloc/realloc/free三、C内存管理方式  3.1 new/delete操作内置类型  3.2 new和delete操作自定义类型  3.3 operator new与operator delete函数 四、new和delete的实现原理  4.1 内置类型…

【Java集合】面试题汇总

Java 集合Java 集合概览1. List, Set, Queue, Map 四者的区别&#xff1f;2. ArrayList 和 Array&#xff08;数组&#xff09;的区别&#xff1f;3. ArrayList 和 Vector 的区别?4. Vector 和 Stack 的区别?&#xff08;了解即可&#xff09;5. ArrayList 可以添加 null 值吗…

python+appium调@pytest.mark.parametrize返回missing 1 required positional argument:

出错描述&#xff1a; 1、在做pythonappium自动化测试时&#xff0c;使用装饰器pytest.mark.parametrize&#xff08;“参数”&#xff0c;[值1&#xff0c;值2&#xff0c;值3]&#xff09;&#xff0c;测试脚本执行返回test_xx() missing 1 required positional argument:“…

Bitmap OOM

老机器Bitmap预读仍然OOM&#xff0c;无奈增加一段&#xff0c;终于不崩溃了。 if (Build.VERSION.SDK_INT < 21)size 2; 完整代码&#xff1a; Bitmap bitmap; try {//Log.e(Thread.currentThread().getStackTrace()[2] "", surl);URL url new URL(surl);…

通俗易懂HTTP和HTTPS区别

HTTP&#xff1a;超文本传输协议&#xff0c;它是使用一种明文的方式发送我们的内容&#xff0c;没有任何的加密&#xff0c;例如我们要在网页上输入账号密码&#xff0c;如果使用HTTP协议&#xff0c;账号密码就可能会被暴露&#xff0c;默认端口是80. HTTPS&#xff1a;是HT…

动态规划解决背包问题

目录 动态规划步骤&#xff1a; 1.01背包问题 2.完全背包问题 动态规划步骤&#xff1a; step1.分析问题&#xff0c;定义dp数组&#xff08;下标含义&#xff09; step2.初始化dp数组&#xff08;边界&#xff09; step3.写dp状态转换方程&#xff08;明确dp数组遍历顺序…

【Super数据结构】二叉搜索树与二叉树的非递归遍历(含前/中/后序)

&#x1f3e0;关于此专栏&#xff1a;Super数据结构专栏将使用C/C语言介绍顺序表、链表、栈、队列等数据结构&#xff0c;每篇博文会使用尽可能多的代码片段图片的方式。 &#x1f6aa;归属专栏&#xff1a;Super数据结构 &#x1f3af;每日努力一点点&#xff0c;技术累计看得…

【饿了么笔试题汇总】[全网首发]2024-04-12-饿了么春招笔试题-三语言题解(CPP/Python/Java)

&#x1f36d; 大家好这里是KK爱Coding &#xff0c;一枚热爱算法的程序员 ✨ 本系列打算持续跟新饿了么近期的春秋招笔试题汇总&#xff5e; &#x1f4bb; ACM银牌&#x1f948;| 多次AK大厂笔试 &#xff5c; 编程一对一辅导 &#x1f44f; 感谢大家的订阅➕ 和 喜欢&#x…

.cur 鼠标光标文件读取

备份icon掩码开发代码-CSDN博客 代码改写自 目前bug是高度不足&#xff0c;顶上的几十个像素图片打印需要加常数&#xff0c; i的改写是 i/3,参考上面链接的自简书的代码 #include <stdio.h> #include <windows.h> #pragma warning(disable : 4996) // visu…

[lesson20]初始化列表的使用

初始化列表的使用 类成员的初始化 C中提供了初始化列表对成员变量进行初始化 语法规则 注意事项 成员的初始化顺序与成员的声明顺序相同成员的初始化顺序与初始化列表中的位置无关初始化列表先于构造函数的函数体执行 类中的const成员 类中的const成员会被分配空间的类中…

【Linux】环境搭建

昙花一现&#xff0c;却等待了整个白昼 蝉鸣一夏&#xff0c;却蛰伏了几个四季 目录 购买云服务器 总结 使用 XShell 远程登陆到 Linux 利用Linux编写一个简单C程序 ⭐toush -- 创建文件 ⭐vi -- 文本编译器 ⭐ll -- 查看文件的显示结果分析 ⭐gcc -o ⭐cat -- 查看源代码 契子…

利用细粒度检索增强和自我检查提升对话式问题解答能力

&#x1f349; CSDN 叶庭云&#xff1a;https://yetingyun.blog.csdn.net/ 论文标题&#xff1a;Boosting Conversational Question Answering with Fine-Grained Retrieval-Augmentation and Self-Check 论文地址&#xff1a;https://arxiv.org/abs/2403.18243 检索增强生成…

【报错】AttributeError: ‘NoneType‘ object has no attribute ‘pyplot_show‘(已解决)

【报错】AttributeError: ‘NoneType’ object has no attribute ‘pyplot_show’ 问题描述&#xff1a;python可视化出现下面报错 我的原始代码&#xff1a; import matplotlib.pyplot as pltplt.figure() plt.plot(x, y, bo-) plt.axis(equal) plt.xlabel(X) plt.ylabe…

最短路径问题——(弗洛伊德算法与迪杰斯特拉算法)

最短路径问题——&#xff08;弗洛伊德算法与迪杰斯特拉算法&#xff09;【板子】 题目&#xff1a; 对于下面的图片所给出的关系,回答下面两个问题&#xff1a; 利用迪杰斯特拉算法求点A到每一个点之间的最小距离。利用弗洛伊德算法求每两个点之间的最短路径。 &#xff0…