NLP之神经网络语言模型(NNLM)_Torch

NNLM的Pytorch实现 import torch import torch.nn as nn import torch.optim as optimizer import torch.utils.data as Data dtype = torch.FloatTensor sentences = ['i like cat','i love coffee','i hate milk'] sentences_list = " ".join(sentences).split() # ['i', 'like', 'cat', 'i', 阅读详情

import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable

dtype = torch.FloatTensor

sentences = [ "i like dog", "i love coffee", "i hate milk"]
word_list = " ".join(sentences).split()
word_list = list(set(word_list))
word_dict = {w: i for i, w in enumerate(word_list)}
number_dict = {i: w for i, w in enumerate(word_list)}
n_class = len(word_dict) # number of Vocabulary
# NNLM Parameter
n_step = 2 # n-1 in paper
n_hidden = 2 # h in paper
m = 2 # m in paper

def make_batch(sentences):
    input_batch = []
    target_batch = []

    for sen in sentences:
        word = sen.split()
        input = [word_dict[n] for n in word[:-1]] # 写出前(n-1)个词所对应的的位置
        target = word_dict[word[-1]] #预测第n个词

        input_batch.append(input)
        target_batch.append(target)

    return input_batch, target_batch
make_batch(sentences)
([[5, 0], [5, 4], [5, 1]], [2, 6, 3])
input_batch = []
target_batch = []
# Model
class NNLM(nn.Module):
    def __init__(self):
        super(NNLM, self).__init__()
        self.C = nn.Embedding(n_class, m)
        self.H = nn.Parameter(torch.randn(n_step * m, n_hidden).type(dtype))
        self.W = nn.Parameter(torch.randn(n_step * m, n_class).type(dtype))
        self.d = nn.Parameter(torch.randn(n_hidden).type(dtype))
        self.U = nn.Parameter(torch.randn(n_hidden, n_class).type(dtype))
        self.b = nn.Parameter(torch.randn(n_class).type(dtype))

    def forward(self, X):
        X = self.C(X)
        X = X.view(-1, n_step * m) # [batch_size, n_step * n_class]
        tanh = torch.tanh(self.d + torch.mm(X, self.H)) # [batch_size, n_hidden]
        output = self.b + torch.mm(X, self.W) + torch.mm(tanh, self.U) # [batch_size, n_class]
        return output

model = NNLM()
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

input_batch, target_batch = make_batch(sentences)
input_batch = Variable(torch.LongTensor(input_batch))
target_batch = Variable(torch.LongTensor(target_batch))
model(input_batch).shape
torch.Size([3, 7])
input_batch.shape
torch.Size([3, 2])
target_batch.shape
torch.Size([3])
input_batch
tensor([[5, 0],
        [5, 4],
        [5, 1]])
model(input_batch)
tensor([[ 2.4777, -1.9615,  3.1095,  1.3201,  2.9772,  1.8934, -3.3565],
        [ 4.5358, -5.6496,  7.6550,  1.0730,  2.4828, -0.2332, -5.0569],
        [ 0.0928,  1.4060,  0.2988,  1.9056,  1.4285,  3.9681, -0.2240]],
       grad_fn=<AddBackward0>)
target_batch
tensor([2, 6, 3])
make_batch(sentences)
([[5, 0], [5, 4], [5, 1]], [2, 6, 3])

# Training
for epoch in range(5000):

    optimizer.zero_grad()
    output = model(input_batch)

    # output : [batch_size, n_class], target_batch : [batch_size] (LongTensor, not one-hot)
    loss = criterion(output, target_batch)
    if (epoch + 1)%1000 == 0:
        print('Epoch:', '%04d' % (epoch + 1), 'cost =', '{:.6f}'.format(loss))

    loss.backward()
    optimizer.step()

# Predict
predict = model(input_batch).data.max(1, keepdim=True)[1]

# Test
print([sen.split()[:2] for sen in sentences], '->', [number_dict[n.item()] for n in predict.squeeze()])

Epoch: 1000 cost = 0.382346
Epoch: 2000 cost = 0.051073
Epoch: 3000 cost = 0.014534
Epoch: 4000 cost = 0.005861
Epoch: 5000 cost = 0.002755
[['i', 'like'], ['i', 'love'], ['i', 'hate']] -> ['dog', 'coffee', 'milk']
predict.shape
torch.Size([3, 1])
predict_1 = model(input_batch)
predict_1.shape
torch.Size([3, 7])
predict
tensor([[5],
        [3],
        [0]])
predict_1
tensor([[ 2.7264, -3.8278,  0.1669,  3.1027, -3.1502, 10.1232, -0.8033],
        [-1.4627, -6.5132, -0.9443,  6.8087, -4.8649, -0.4327, -3.6853],
        [ 6.9640, -3.6173, -0.7420, -2.6381, -4.1076, -0.5775, -3.9949]],
       grad_fn=<AddBackward0>)

# pad documents to a max length of 4 words
max_length = 4
padded_docs = pad_sequences(encoded_docs, maxlen=max_length, padding='post')
print(padded_docs)
# define the model
input = Input(shape=(4, ))
x = Embedding(vocab_size, 8, input_length=max_length)(input)
x = Flatten()(x)
x = Dense(1, activation='sigmoid')(x)
model = Model(inputs=input, outputs=x)
# compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])
# summarize the model
print(model.summary())
# fit the model
model.fit(padded_docs, labels, epochs=50, verbose=0)
# evaluate the model
loss, accuracy = model.evaluate(padded_docs, labels, verbose=0)
print('Accuracy: %f' % (accuracy * 100))


pytorch入门NLP教程(一)——NNLM 用pytorch带你学习NLP,让我们一起进步吧~ 阅读详情

相关推荐

从Word2Vec到BERT:前馈网络(FFNN)在NLP进化史中扮演了什么角色?

本文探讨了前馈网络(FFNN)在NLP技术演进中的关键作用,从Word2Vec到BERT的进化历程。FFNN作为现代自然语言处理的基石,通过词嵌入雏形、上下文窗口处理和非线性特征组合等突破性贡献,塑造了NLP的基因密码。文章还分析了FFNN在Transformer架构中的隐形基因及其在现代NLP任务中的持续价值。

weixin_30920853的博客 305

Pytorch实现NNLM语言模型

Pytorch实现NNLM语言模型

linxizi0622的博客 411

【AI应用开发工程师】第三章:大语言模型原理

摘要 本文系统介绍了大规模语言模型(LLM)的核心原理与技术演进。从N-gram统计语言模型开始,分析了其数据稀疏、长距离依赖不足等局限。重点阐述了神经语言模型的突破性进展,包括词向量表示、Transformer架构优势,以及自回归生成机制。详细讲解了三种预训练目标(CLM/MLM/Prefix LM)及其区别,并深入剖析了KV Cache加速、解码策略(Greedy/Top-k/Top-p等)等关键技术。同时探讨了涌现能力现象、Scaling Law规律,以及主流LLM架构差异。文章通过数学公式、对比表格

sjy8207380的专栏 300

使用Pytorch实现NLP深度学习

原文链接:https://pytorch.org/tutorials/beginner/deep_learning_nlp_tutorial.html 本文将会帮助你了解使用Pytorch进行深度学习编程的关键思想。一些章节内容(计算图和梯度)不是Pytorch所特有的,而是所有深度学习工具包都包含的内容。 本文旨在为那些从未接触过其它深度学习框架(如TensorFlow,Theano,...

hbu_pig的专栏 1万+

PyTorch的nn.Module类的详细介绍

在PyTorch中,nn.Module类是构建神经网络模型的基础类,所有自定义的层、模块或整个神经网络架构都需要继承自这个类。nn.Module类提供了一系列属性和方法用于管理网络的结构和训练过程中的计算。

xw555666的博客 7705

自然语言处理1(NLP)------NLP--Basic Embedding Model

NLP–Basic Embedding Model 1-1. NNLM(Neural Network Language Model) - Predict Next Word Paper下载 代码块 NNLM-Tensor.py @Tae Hwan Jung @graykode import tensorflow as tf import numpy as np tf.reset_d...

weixin_41697507的博客 776

NLP-1:NNLM pytorch

对应到number_dict {0: 'hate', 1: 'milk', 2: 'dog', 3: 'i', 4: 'coffee', 5: 'like', 6: 'love'}中查找。nn.Linear(n_step * m, n_hidden, bias=False) 把维度从n_step * m 变成了 n_hidden,也就是从4变到2。改变了原来的输入[[4, 6], [4, 0], [4, 3]] 但是shape最里层的[4,6]中的4改成了[-0.3372, 0.5522],以此类推。

conglanjun的博客 861

Ubuntu下OpenOCD+GDB的安装、编译及使用

目标开发板(芯片):stm32mp157aaa 仿真器:ST-Link 操作系统:Ubuntu 18.04 调试软件:OpenOCD OpenOCD的安装 首先下载OpenOCD有多种方式,可以GitHub上下载,目录下打开终端,输入 git clone git://git.code.sf.net/p/openocd/code openocd 下载完整的OpenOCD的文件夹。进入到OpenOCD的目录下,开始安装。 接着,OpenOCD适用于微处理器的debug和烧写,需要下载相关库 sud

蓝冰露的博客 9524

【NLP】神经网络语言模型(NNLM)

背景 语言模型也经常会在NLP中提出。在深度学习大行其道的今天基于神经网络的语言模型与传统定义的又有什么区别呢?语言模型在NLP中有什么意义呢?不妨沉下心,了解一下。 语言模型是一个单纯的、统一的、抽象的形式系统,语言客观事实经过语言模型的描述,比较适合于电子计算机进行自动处理,因而语言模型对于自然语言的信息处理具有重大的意义。换一句话说,语言模型其实就是看一句话是不是正常人说出来的正常的话。语言模型在信息检索、机器翻译、语音识别中担任着重要的任务。比如机器翻译、语音识别得到若干候选之后,可以利用语言模型挑

让算法融入生活,改变生活! 1776

433MHz无线通信

基本概念 工作频率:433.92MHz 调制方式:ASK/OOK,FSK,GFSK 现有遥控与接收器方案中,多数使用ASK/OOK调试方式。ASK即“幅移键控”又称为“振幅键控”,也有称为“开关键控”(通断键控)的,所以又记作OOK(On-Off keyed)信号。ASK是一种相对简单的调制方式。幅移键控(ASK)相当于模拟信号中的调幅,不同的是与载频信号相乘的是二进制数码。幅移就是把频...

沧海孤叶的博客 5万+

增量式PID的P和I怎么理解(一)

增量式PID的P、I理解之推翻片 据我所知的资料里关于PID三个参数的理解是这样的:(我这里只说P和I,先不说D) P的作用:比例P可以加快系统调节速度,P过小调节时间变长,响应性不够,P越大响应性越高超调也越严重,过大的P会使系统振荡。 I的作用:消除静差,提高控制精度,I越大越滞后,过大会使系统振荡。 ...

fangchenglia的博客 1万+

NLP-tutorial代码笔记1

现在开的坑系列是Github上一个即将3k+Star的NLP-tutorial项目,里面是一些NLP方面的Deep-learning代码,框架Tensor和Torch都有,而且实现行数基本都控制在了100行以内,比较适合去研究一下。这样之后搭框架的时候就会明白许多了。 项目地址:https://github.com/graykode/nlp-tutorial 第一部分是基本的Embeddeding...

Raymond编程路 1226

IB网络下不同租户业务隔离方案

IB(InfiniBand)网络隔离可以在不同的通信模式下实现,其中包括 IPoIB(IP over InfiniBand)通信模式。在 IPoIB 模式下,InfiniBand 网络可以承载 IP 数据包,使得基于 IP 的应用程序能够在 InfiniBand 网络上进行通信。在这种情况下,IB 网络隔离通常指通过配置 Partition Key(PKey)来实现不同的租户或应用程序之间的网络隔离。然而,IB 网络隔离并不仅限于 IPoIB 模式。

guganly的专栏 1527

NLP基础:从词嵌入到语言模型的实践指南

自然语言处理(NLP)是人工智能领域的重要分支,致力于让计算机理解人类语言。其核心技术包括文本表示和语言模型两大方向。文本表示经历了从离散表示(如One-hot编码、词袋模型)到分布式表示(如Word2Vec词嵌入)的演进,词嵌入通过低维连续向量有效捕捉语义关系。语言模型则从统计方法(n-gram)发展到神经网络模型(RNN、Transformer)。在实际工程中,词向量训练需注意学习率设置和数据清洗,而处理长文本时可采用TF-IDF或分块策略。掌握这些基础技术后,可进一步学习BERT、GPT等现代大语言模

weixin_30363981的博客 402

spark3.x 写入hudi报错

【代码】spark3.x 写入hudi报错。

W2484980893的博客 1578

Jetson Orin NX深度学习环境配置全攻略:从JetPack到PyTorch避坑指南

本文提供Jetson Orin NX深度学习环境配置的完整避坑指南。重点讲解如何正确利用JetPack SDK作为系统基石,使用Miniforge管理Python环境,并安装与CUDA版本严格匹配的PyTorch特供版本。通过详细的步骤和验证方法,帮助开发者在ARM架构的嵌入式平台上高效搭建稳定的AI开发工作站。

yolo5detector的博客 272

100行代码掌握NLP核心模型:nlp-tutorial让你快速入门自然语言处理

想学习自然语言处理技术却不知从何入手?面对复杂的神经网络架构感到迷茫?nlp-tutorial项目为你提供了完美的解决方案——用不到100行代码实现每个NLP核心模型,让深度学习变得简单易懂。🎯 这个基于PyTorch的自然语言处理教程专为初学者和研究者设计,通过精简的代码展示NLP技术的精髓。 ## 为什么选择nlp-tutorial作为你的NLP学习起点? **nlp-tutorial*

gitblog_00210的博客 424

CMOS图像传感器——工作原理

CMOS图像传感器的曝光与读出

沧海一升的博客 9459

如何高效掌握自然语言处理?nlp-tutorial实战指南助你快速上手

想要在短时间内掌握自然语言处理的核心技术吗?nlp-tutorial项目为你提供了一条高效的学习路径。这个基于PyTorch的NLP教程集合了从基础到前沿的完整技术栈,每个模型的实现代码都控制在100行以内,让深度学习研究者能够快速理解核心原理并应用于实际项目。 ## 为什么选择nlp-tutorial进行NLP学习? 自然语言处理是现代人工智能领域的关键技术,但复杂的理论和冗长的代码往往让初

gitblog_00027的博客 403

【深度学习】什么是自回归模型?

自回归模型是一种重要的时间序列模型,通过利用过去的值来预测当前或未来的值。它在统计学、经济学、自然语言处理等领域有广泛的应用。自回归模型的简单性和可解释性使其成为许多应用的首选,但在更复杂的情况下,可能需要结合其他模型如移动平均模型(MA模型)或混合模型(如ARIMA)来更好地捕捉时间序列中的模式。扩散模型(Diffusion Model)和自回归模型(Autoregressive Model)是两种不同的生成模型,各自有独特的特点和应用场景。

q742971636的博客 1670

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

终极NLP教程:如何在100行代码内掌握自然语言处理核心技术?

想要快速掌握自然语言处理的核心技术却不知从何开始?nlp-tutorial项目为你提供了一套完整的PyTorch自然语言处理学习方案,每个模型的实现都控制在100行代码以内,让深度学习研究者和技术开发者能够高效学习NLP技术栈。这个开源免费的实用教程涵盖了从基础词嵌入到先进Transformer模型的完整技术路线,特别适合需要快速上手NLP应用的开发者。 ## 🚀 为什么选择nlp-tutor

gitblog_00063的博客 1096

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

正弦函数激活在FFN语言模型中的创新应用

在神经网络语言模型(NNLM)中,激活函数的选择直接影响模型的特征提取能力。传统ReLU等函数在处理长序列时存在梯度消失问题,而正弦函数的周期性特性使其能更好地捕捉语言中的层次结构。通过将正弦激活引入前馈神经网络(FFN),不仅保持了Transformer架构的参数效率,还在PTB、WikiText等基准测试中实现了3-8%的困惑度提升。这种改进特别适合处理长距离依赖关系,为资源受限场景下的语言模型优化提供了新思路。关键技术包括可学习频率参数和混合激活策略,这些创新点使模型能自适应不同语法层级的特征表示。

weixin_33725270的博客 391

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

NLP-语言模型

语言模型 1、语言模型的概念 语言模型(language model)是自然语言处理的重要技术。自然语言处理中最常见的数据就是文本数据。我们可以把一段自然语言文本看作一段离散的时间序列。假设一段长度为TTT的文本中的词依次为w1,w2,⋯ ,wTw_1,w_2,\cdots ,w_Tw1​,w2​,⋯,wT​,那么在离散的时间序列中,wt(1≤t≤T)w_t(1\le t \le T)wt​(1≤t≤T)可以看作在时间步ttt的输出或者标签。给定一个长度为TTT的序列w1,w2,⋯ ,wTw_1,w_2,\

tcn760的博客 5446

NLP语言模型概览

Pre-trained Language Model(PLM)模型BERT 具有两种输出,一个是pooler output,对应的[CLS]的输出,以及sequence output,对应的是序列中的所有字的最后一层hidden输出。所以BERT主要可以处理两种,一种任务是分类/回归任务(使用的是pooler output),一种是序列任务(sequence output)

noobiee的博客 4761

NLP常见语言模型总结

目录 一、词的离散表示 1、One-hot编码(独热编码) 2、Bag of Words(BOW,词袋模型) 3、N-gram语言模型 二、词的分布式表示(Distributed Representation) 1、共现矩阵(Co-currence Matrix) 2、神经网络语言模型(Neural Network Language Model,NNLM) 3、Word2Vec,G...

分享实践与思考 2万+
上一篇: SVM练习
下一篇: NLP之word2vec,使用tensorflow2.0
潘诺西亚的火山
博客等级 码龄10年 7415粉丝 283原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘诺西亚的火山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值