Lecture 7 Deep Learning for NLP: Feedforward Networks

news2024/10/7 18:24:01

目录

      • Deep Learning
      • Feedforward Neural Network 前馈神经网络
      • Neuron 神经元
      • Output Layer 输出层
      • Optimization
      • Regularization 正则化
      • Topic Classification 主题分类
      • Language Model as Classifiers 语言模型作为分类器
      • Word Embeddings 词嵌入
      • Training a Feed-Forward Neural Network Language Model 训练前向传播神经网络语言模型
      • Feed-Forward Neural Network for POS Tagging 用于词性标注的前向传播神经网络
      • Convolutional Networks 卷积网络
      • Convolutional Networks for NLP

Feedforward Neural Networks Basics

Deep Learning

  • A branch of machine learning 机器学习的一个分支

  • Re-branded name for neural networks 神经网络的重命名

  • Deep: Many layers are chained together in modern deep learning models 深度:现在深度学习模型中的链式链接的多层

  • Neural Networks: Historically inspired by the way computation works in the brain 神经网络:历史上受大脑计算方式的启发

    • Consists of computation units called neurons 由称为神经元的计算单元组成

Feedforward Neural Network 前馈神经网络

  • Also called multilayer perceptron 也被称为多层感知机

  • E.g. of architecture: 架构示例

    在这里插入图片描述

  • Each arrow carries a weight, reflecting its importance 每个箭头都会携带一个权重,以反应其重要性

  • Certain layers have non-linear activation functions 某些层具有非线性的激活函数

Neuron 神经元

  • Each neuron is a function: 每个神经元是一个函数

    • Given input x, compute real-value h: 给定输入x,计算实值h



    在这里插入图片描述

    • Scales input (with weights, w) and adds offset (bias, b) 通过权重w缩放输入并添加偏移量(偏置,b
    • Applies non-linear function, such as logistic sigmoid, hyperbolic sigmoid(tanh), or rectified linear unit 应用非线性函数,如逻辑sigmoid、双曲sigmoid(tanh)或修正线性单元
    • w and b are parameters of the model wb 是模型的参数
  • Typically hava several hidden units 通常有几个隐藏单元. E.g.

    • Each with its own weights wi, and bias terms bi 每个单元都有自己的权重 wi,和偏置项 bi

    • Can be expressed using matrix and vector operators 可以使用矩阵和向量运算符表示:

    • Where is a matrix comprising the weight vectors and 是一个包含权重向量的矩阵 is a vector of all bias terms 是所有偏置项的向量

    • Non-linear function applied element-wise 非线性函数逐元素应用

Output Layer 输出层

  • For binary classification problem: Sigmoid Activation Function 对于二元分类问题:Sigmoid 激活函数

  • Multi-class classification problem: Softmax Activation Function ensures probabilities are greater than 0 and sum to 1 多类分类问题:Softmax 激活函数确保概率大于0且和为1:

Optimization

  • Consider how well the model fits the training data, in terms of the probability it assigns to the correct output 考虑模型如何拟合训练数据,即它对正确输出所分配的概率

    • Want to maximize total probability L 想要最大化总概率 L

    • Equivalently minimize -log L with respect to parameters 等价地,以参数最小化 -log L

  • Trained using gradient descent 使用梯度下降进行训练

    • Tools like tensorflow, pytorch, dynet use autodiff to compute gradients automatically 像 tensorflow, pytorch, dynet 这样的工具用于自动计算梯度

Regularization 正则化

  • Have many parameters, so the model overfits easily 有许多参数,所以模型很容易过拟合

  • Low bias, high variance 偏差较低,方差较高

  • Regularization is very import in neural networks 在神经网络中,正则化非常重要

  • L1-norm: sum of absolute values of all parameters L1范数:所有参数的绝对值之和

  • L2-norm: sum of squares of all parameters L2范数:所有参数的平方之和

  • Dropout: randomly zero-out some neurons of a layer Dropout:随机将某一层的部分神经元值设为零

    • If a dropout rate = 0.1, a random 10% of neurons now have 0 values 如果Dropout比率 = 0.1,那么随机10%的神经元现在的值为0

    在这里插入图片描述

    • Can apply dropout to any layer, but in practice, mostly to the hidden layers 可以在任何层应用dropout,但实际上,主要应用于隐藏层

Applications in NLP

Topic Classification 主题分类

  • Given a document, classify it into a predefined set of topics. E.g. economy, politics, sports 给定一个文档,将其分类到预定义的主题集合中。例如:经济,政治,体育

  • Input: Bag-of-words 输入:词袋模型

    Example input:

    在这里插入图片描述

  • Training:

    Architecture:

    在这里插入图片描述


    Hidden Layers:






    • Randomly initialize W and b
    • E.g:

      Input:

      Output: : Probability distribution over

      Loss: if true label is

  • Prediction:

    • E.g.

      Input:

      Output:

      Predicted class is

  • Potential Improvements: 可能的改进

    • Use Bag of bigrams as input 使用bigrams的词袋作为输入
    • Preprocess text to lemmatize words and remove stopwords 预处理文本,对词进行词元化并去除停用词
    • Instead of raw counts, can weight words using TF-IDF or indicators 可以使用TF-IDF或指标来权衡单词,而不是原始计数

Language Model as Classifiers 语言模型作为分类器

  • Language Models can be considered simple classifiers 语言模型可以被视为简单的分类器.

    • E.g. For a trigram model: classifies the likely next word in a sequence, given salt and and 给出了在给定 saltand 的情况下,可能的下一个词的分类
  • Feedforward Neural Network Language Model 前向传播神经网络语言模型

    • Use neural network as a classifier to model 使用神经网络作为分类器来模型
    • Input features: The previous words 输入特征:前面的单词
    • Output classes: the next word 输出类别:下一个单词
    • Use Word Embeddings to represent each word 使用词嵌入来表示每个单词
      • E.g. of Word Embeddings: 词嵌入的例子

        在这里插入图片描述

Word Embeddings 词嵌入

  • Maps discrete word symbols to continuous vectors in a relatively low dimensional space 将离散的词符号映射到相对较低维度的连续向量空间中

  • Word embeddings allow the model to capture similarity between words 词嵌入允许模型捕获单词之间的相似性

  • In feed-forward neural network language model, the first layer is the sum of input word embeddings 在前向传播神经网络语言模型中,第一层是输入词嵌入的和

Training a Feed-Forward Neural Network Language Model 训练前向传播神经网络语言模型

  • E.g.

  • Lookup word embeddings () for a, cow, and eats

  • Concatenate them and feed it to the network 将它们连接起来并输入网络:

  • gives the probability distribution over all words in the vocabulary 给出了所有词汇表中单词的概率分布

    • E.g.

    在这里插入图片描述


  • Loss:

  • Most parameters are in the word embeddings W1 (size = d * |V|) and the output embeddings W3 (size = |V| * d) 大部分参数都在词嵌入 W1 (大小 = d * |V|) 和输出嵌入 W3 (大小 = |V| * d)

  • Example Architecture:

    在这里插入图片描述

  • Problem of Count-based N-gram models: 基于计数的N-gram模型的问题

    • Cheap to train 便宜的训练
    • Problems with sparsity and scaling to larger contexts 在稀疏性和大规模上下文的扩展性上存在问题
    • Don’t adequately capture properties of words 不能充分捕获单词的属性
  • Advantages of Feed-Forward Neural Network Language Model: 前向传播神经网络语言模型的优点

    • Automatically capture word properties, leading to more robust estimates 自动捕获单词的属性,导致更稳健的估计

Feed-Forward Neural Network for POS Tagging 用于词性标注的前向传播神经网络

  • POS tagging can also be framed as classification: 词性标注也可以被框定为分类

    • -> classifies the likely POS tag for eatseats的可能的词性标签进行分类
  • Feed-Forward Neural Network Language Model architecture can be adapted to the task directly 前向传播神经网络语言模型的架构可以直接适应这个任务

  • Inputs:

    • recent words 最近的词:
    • recent tags 最近的标签:
  • Outputs:

    • current tags:
  • Frame as neural network with:

    • 5 inputs: 3 word embeddings and 2 tag embeddings 5个输入:3个词嵌入和2个标签嵌入
    • 1 output: vector of size |T|, using softmax 1个输出:大小为|T|的向量,其中|T|是词性标签集的大小
  • Training to minimize:

  • Example Architecture:

    在这里插入图片描述

Convolutional Networks

Convolutional Networks 卷积网络

  • Commonly used in computer vision 常用于计算机视觉

  • Identify indicative local predictors 确定指示性本地预测因子

  • Combine them to produce a fixed-size representation 将它们合并,形成固定大小的表示

Convolutional Networks for NLP

  • Sliding window over sequence 按顺序滑动窗口

  • W = convolution filter (linear transformation + tanh) W = 卷积滤波器(线性变换+tanh)。

  • max-pool to produce a fixed-size representation max-pool来产生一个固定大小的表示

  • Example architecture:

    在这里插入图片描述

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

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

相关文章

RVOS操作系统协作式多任务切换实现-03

RVOS操作系统协作式多任务切换实现-03 任务(task)多任务 (Multitask)任务上下文(Context)多任务系统的分类协作式多任务 创建和初始化第 1 号任务切换到第一号任务执行协作式多任务 - 调度初始化和任务创建…

虚拟机-安装与使用2023

虚拟机-安装与使用 前言 一、虚拟机 1.VMware 2.Virtualbox 二、VMware 的下载 三、VMware 的安装 四、验证是否安装成功 五、运行 VMware 六、VMware 上安装其它操作系统 安装 Windows 10安装 CentOS-Linux安装 Kali-Linux 七、VMware 常用功能同步时间系统备份克隆快照内存设…

黑马Redis视频教程高级篇(多级缓存案例导入说明)

目录 一、安装MYSQL 1.1、准备目录 1.2、运行命令 1.3、修改配置 1.4、重启 二、导入SQL 三、导入Demo工程 3.1、分页查询商品 3.2、新增商品 3.3、修改商品 3.4、修改库存 3.5、删除商品 3.6、根据id查询商品 3.7、根据id查询库存 3.8、启动 四、导入商品查询…

Maven高级——私服(完结撒花!)

作用与介绍 一个公司内有两个项目组,如果其中一个开发了一个依赖tlias-utils,另一个项目组要使用的话要么就是传过来直接install放到自己的本地仓库里面的。 但是也可以搭建一个公共仓库,专门供公司局域网内部使用,也就是所谓私服。 然后在…

chatgpt赋能python:Python反向函数:在编程中的威力

Python反向函数:在编程中的威力 在Python中,反向函数是一个强大且常用的工具,可以帮助程序员在编写代码时更加高效和精确地处理数据。在本文中,我们将讨论Python反向函数的用途和实现,并详细介绍如何在您的代码中使用…

Java007——Java注释介绍

围绕以下3点介绍: 1、什么是Java注释? 2、Java注释的作用? 3、Java注释长什么样,以及怎么使用Java注释? 一、什么是Java注释? Java注释是在Java程序中用来描述代码的特殊语句。 注释被忽略并且不被编译器…

MySQL表的增删改查

目录 一、Create 1.insert 2.更新 3.替换 二、Retrieve(查找) 1.select 2.where 3. 结果排序 4. 筛选分页结果 三、Update 四、Delete 1.删除数据 2.截断表 五、聚合函数 1.count: 2.avg 3.sum 4.max 5.min 六、Group …

微信小程序开发实战 ②④(自定义 TabBar练习)

作者 : SYFStrive 博客首页 : HomePage 📜: 微信小程序 📌:个人社区(欢迎大佬们加入) 👉:社区链接🔗 📌:觉得文章不错可以点点关注 &#x1f4…

十四、神经风格迁移

文章目录 1、神经风格迁移2、生成图片的代价函数THE END 1、神经风格迁移 \qquad 神经风格迁移就是将一幅原有的图片(content picture, C),对照着一幅风格图片(style picture, S),生成一幅新的图片(generated picture, G),如下图所示&#xf…

k8s istio 集成 多版本应用服务 和 网格监测

说明 博客文章地址:https://blog.taoluyuan.com/posts/istio-getting-started/ 本主要是内容: 使用 istioctl 安装 istio采用 istio 官方提供 的 应用bookinfo,实现多版本的服务应用部署istio 网关 gateway,vs,dr 的基本使用利用监测工具 prometheus,grafana,jaeger 查看 ist…

关于EMC Unity 存储系统DIMM内存的几个问题

下面是客户咨询最多的几个关于EMC Unity的DIMM内存的问题,供大家参考。 1. Unity存储能否自己扩容内存 有客户觉得Unity存储的内容太小,想自己扩容内存,很朴实的想法,原来是每个控制器3条16gb,能不能升级到3条32gb或…

基于Mybatis-Plus拦截器实现MySQL数据加解密

一、背景 用户的一些敏感数据,例如手机号、邮箱、身份证等信息,在数据库以明文存储时会存在数据泄露的风险,因此需要进行加密, 但存储数据再被取出时,需要进行解密,因此加密算法需要使用对称加密算法。 常…

Unreal5 第三人称射击游戏 射击功能实现1

状态机的缓存 状态机缓存功能相当于我们只需要实现一次,可以在多个地方引用,也可以在别的状态机里面使用,而不是在里面再重新写一遍相应的功能。 我们可以在基础状态机的链接拉出一条线,搜索“缓存” 第一个就是新保存的缓存姿势…

Qt OpenGL(四十二)——Qt OpenGL 核心模式-GLSL(二)

提示:本系列文章的索引目录在下面文章的链接里(点击下面可以跳转查看): Qt OpenGL 核心模式版本文章目录 Qt OpenGL(四十二)——Qt OpenGL 核心模式-GLSL(二) 冯一川注:GLSL其实也是不断迭代的,比如像3.3版本中,基本数据类型浮点型只支持float型,而GLSL4.0版本开始就…

chatgpt赋能python:Python单位换算—让编程更精确的工具

Python单位换算—让编程更精确的工具 作为一名10年经验的Python工程师,我深深认识到在各种计算机领域的重要性。它可以帮助我们进行大量数据的计算和转换,其中的单位换算是其中一个重要的子领域。 单位换算对编程的重要性 无论是在科学研究还是工业生…

序贯最小二乘平差 VS 卡尔曼滤波

文章目录 Part.I IntroductionPart.II 概念比较Chap.I 序贯最小二乘平差Chap.II 卡尔曼滤波Chap.III 比较 Reference Part.I Introduction 序贯最小二乘平差和卡尔曼滤波有些相似,但是还是有一些区别: 序贯最小二乘平差用来处理静态数据,也…

层次多尺度注意力用于语义分割

层次多尺度注意力用于语义分割 HIERARCHICAL MULTI-SCALE ATTENTION FOR SEMANTIC SEGMENTATION https://arxiv.org/pdf/2005.10821.pdf 摘要 多尺度推断通常用于提高语义分割的结果。多个图像尺度通过网络传递,然后使用平均或最大池化方法将结果组合起来。在本文…

活用Excel高级筛选解决实际问题

一朋友遇到一个难题:一个电子行业文档,数据中有一项为输出电压,有固定值比如24V、48V等;也有范围值比如10V-60V或者40V-50V,数据不规则,且数量庞大。需要对数据进行分析,筛选出有效数据&#xf…

Spring Bean生命周期之(1)BeanDefinition

文章目录 1 BeanDefinition1.1 Spring Bean 读取解析配置信息1.1.1 XML 配置的处理主要使用的事例1.1.2 注解 BeanDefinition 解析示例 1.2 spring bean 注册阶段1.3 Spring BeanDefinition 合并阶段1.3.1 BeanDefinition 合并示例1.3.2 源码分析 1 BeanDefinition 在spring b…

机器学习——线性回归篇

基本概念 什么是回归预测?什么是分类预测? 模型输入变量预测结果应用回归预测实值离散一个连续值域上的任意值预测值的分布情况分类预测实值离散两个或多个分类值将输入变量分类到不同类别 思考一个问题:分类问题是否可以转变为回归问题&am…