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

建网站的论坛软文有哪些发布平台

建网站的论坛,软文有哪些发布平台,重庆市建设工程造价信息网爬虫,网站建设2018一、说明 句子(短语或段落)级别嵌入通常用作许多 NLP 分类问题的输入,例如,在垃圾邮件检测和问答 (QA) 系统中。在我上一篇文章发现不同级别的BERT嵌入的趋势中,我讨论了如何生成一个向量表示&a…

一、说明

        句子(短语或段落)级别嵌入通常用作许多 NLP 分类问题的输入,例如,在垃圾邮件检测和问答 (QA) 系统中。在我上一篇文章发现不同级别的BERT嵌入的趋势中,我讨论了如何生成一个向量表示,该表示包含有关上下文嵌入值相对于同一令牌的静态嵌入的变化的信息,然后您可以将其用作生成句子级嵌入的组件。本文扩展了此主题,探讨了您需要从句子中的哪些标记中派生此类趋势向量,以便能够为整个句子生成有效的嵌入。

二、直觉

        与此相关的第一个问题是:您需要从句子中的多少个标记中派生嵌入才能为整个句子生成有效的嵌入?如果你还记得上一篇文章中的讨论,我们得到了一个向量——派生为句子中最重要的单词——其中包括有关整个句子上下文的信息。但是,为了更好地了解句子上下文,最好为与该最重要的单词在语法上最相关的单词提供这样的向量。我们为什么需要这个?

        生活中一个简单的类比可以帮助回答这个问题:如果你坐在塔内的餐厅里欣赏周围的美景,你考虑的景色将不包括塔本身。要拍摄塔楼景观的照片,您首先需要离开塔楼。

        好的,我们如何确定与句子中最重要的单词在语法上最相关的单词?(也就是说,您需要根据前面的类比决定拍摄塔的最佳位置)答案是:借助注意力权重,您也可以从BERT模型获得。

三、实现

        在遵循本文其余部分讨论的代码之前,您需要参考上一篇文章中提供的示例(我们将使用该示例中定义的模型和派生向量表示)。您需要做的唯一更正如下: 创建模型时,请确保使模型不仅返回隐藏状态,还返回注意力权重:

model = BertModel.from_pretrained(‘bert-base-uncased’,output_hidden_states = True, # so that the model returns all hidden-states.output_attentions = True) 

        其他所有内容,包括例句,都可以不加修改地使用。实际上,我们只使用第一个例句:“我想要一个苹果。

        下面我们将确定语法上最接近最重要单词的单词(在这个特定示例中为 Want)。为此,我们检查所有 12 层中的注意力权重。首先,我们创建一个空数组(我们不计算特殊符号,不包括第一个和最后一个符号):

a = np.empty([0, len(np.sum(outputs[0].attentions[0][0][11].numpy(), axis=0)[1:-1])])

接下来,我们填写注意力权重矩阵:

for i in range(12):a = np.vstack([a,np.sum(outputs[0].attentions[0][0][i].numpy(), axis=0)[1:-1]])

我们对标点符号不感兴趣。因此,我们将删除矩阵中的最后一列:

a = np.delete(a, -1, axis=1)

所以我们的矩阵现在看起来如下(12x4,即 12 层和 4 个单词)

print(a)
[[0.99275106 1.00205731 0.76726311 0.72082734][0.7479955 1.16846883 0.63782167 1.39036024][1.23037624 0.40373796 0.57493907 0.25739866][1.319888 1.21090519 1.37013197 0.7479018 ][0.48407069 1.15729702 0.54152751 0.57587731][0.47308242 0.61861634 0.46330488 0.47692096][1.23776317 1.2546916 0.92190945 1.2607218 ][1.19664812 0.51989007 0.48901123 0.65525496][0.5389185 0.98384732 0.8789593 0.98946768][0.75819892 0.80689037 0.5612824 1.10385513][0.14660755 1.10911655 0.84521955 1.00496972][0.77081972 0.79827666 0.45695013 0.36948431]]

        现在让我们确定 Want 的哪些层(索引为 1 的第二列)最受关注:

print(np.argmax(a,axis=1))
b = a[np.argmax(a,axis=1) == 1]
array([1, 3, 0, 2, 1, 1, 3, 0, 3, 3, 1, 1])

        接下来,我们可以确定在 Want 处于领先地位的层中,哪个令牌在 Want 之后引起更多关注。为此,我们首先删除“想要”列,然后探索其余三个:

c = np.delete(b, 1, axis=1)
d = np.argmax(c, axis =1)
print(d)
counts = np.bincount(d)
print(np.argmax(counts))
[0 2 2 2 0]
2

        上面显示,我们有苹果这个词(在这里删除Want之后,Apple的索引是2)作为与单词Want在语法上最相关的一个。这是意料之中的,因为这些词分别表示直接宾语和及物动词。

_l12_1 = hidden_states[0][12][0][4][:10].numpy()
_l0_1 = hidden_states[0][0][0][4][:10].numpy()
_l0_12_1 = np.log(_l12_1/_l0_1)
_l0_12_1 = np.where(np.isnan(_l0_12_1), 0, _l0_12_1)

        现在让我们比较一下从单词Apple和Want的嵌入派生的向量。

print(_l0_12_1)
array([ 3.753544 , 1.4458075 , -0.56288993, -0.44559467, 0.9137548 ,0.33285233, 0. , 0. , 0. , 0. ],dtype=float32)print(l0_12_1) # this vector has been defined in the previous post
array([ 0. , 0. , 0. , 0. , -0.79848075,0.6715901 , 0.30298436, -1.6455574 , 0.1162319 , 0. ],dtype=float32)

        如您所见,上述两个向量中的一对匹配元素中的一个值在大多数情况下为零,而另一个值为非零 — 即向量看起来互补(记住塔视图类比:从塔上可以看到相邻的景点,但为了看到塔本身——也许是主要景点——你需要离开它)所以, 您可以安全地按元素对这些向量求和,以将可用信息组合到单个向量中。

s = _l0_12_1 + l0_12_1
print(s)
array([ 3.753544 , 1.4458075 , -0.56288993, -0.44559467, 0.11527407,1.0044425 , 0.30298436, -1.6455574 , 0.1162319 , 0. ],dtype=float32)

        上面的向量接下来可以用作句子级分类的输入。

四、结论

        本文提供了从静态嵌入转向上下文嵌入时如何根据令牌级 BERT 嵌入的趋势生成句子级嵌入的直观信息以及代码。然后,可以将此句子级嵌入用作BERT生成的用于句子分类的CLS令牌嵌入的替代方法,这意味着您可以尝试这两种方法,看看哪一个最适合您的特定问题。


文章转载自:
http://pressural.mnqg.cn
http://irrespectively.mnqg.cn
http://diaspora.mnqg.cn
http://tamure.mnqg.cn
http://normality.mnqg.cn
http://cosmochemistry.mnqg.cn
http://postglacial.mnqg.cn
http://timbul.mnqg.cn
http://merchandiser.mnqg.cn
http://mycetozoan.mnqg.cn
http://hogly.mnqg.cn
http://inoxidizable.mnqg.cn
http://abundant.mnqg.cn
http://ko.mnqg.cn
http://incrassated.mnqg.cn
http://nonevent.mnqg.cn
http://petting.mnqg.cn
http://interlinear.mnqg.cn
http://poltergeist.mnqg.cn
http://orthodromic.mnqg.cn
http://lansing.mnqg.cn
http://infect.mnqg.cn
http://generativist.mnqg.cn
http://trinitytide.mnqg.cn
http://friability.mnqg.cn
http://gcm.mnqg.cn
http://snort.mnqg.cn
http://villainous.mnqg.cn
http://alackaday.mnqg.cn
http://nte.mnqg.cn
http://morpheme.mnqg.cn
http://dodad.mnqg.cn
http://periodontal.mnqg.cn
http://deafness.mnqg.cn
http://enceladus.mnqg.cn
http://frig.mnqg.cn
http://lipositol.mnqg.cn
http://ben.mnqg.cn
http://aluminography.mnqg.cn
http://schoolman.mnqg.cn
http://garri.mnqg.cn
http://expositorily.mnqg.cn
http://tourniquet.mnqg.cn
http://luminaire.mnqg.cn
http://isallotherm.mnqg.cn
http://roentgenometer.mnqg.cn
http://snake.mnqg.cn
http://kapellmeister.mnqg.cn
http://fi.mnqg.cn
http://responseless.mnqg.cn
http://derange.mnqg.cn
http://estaminet.mnqg.cn
http://robust.mnqg.cn
http://harshness.mnqg.cn
http://underlayer.mnqg.cn
http://convolvulus.mnqg.cn
http://matriarchy.mnqg.cn
http://octavian.mnqg.cn
http://transferee.mnqg.cn
http://improvvisatrice.mnqg.cn
http://fidate.mnqg.cn
http://semisocialist.mnqg.cn
http://gallimaufry.mnqg.cn
http://evanescent.mnqg.cn
http://apparently.mnqg.cn
http://lazyback.mnqg.cn
http://evacuator.mnqg.cn
http://faithless.mnqg.cn
http://nsf.mnqg.cn
http://multilocular.mnqg.cn
http://estivation.mnqg.cn
http://psychometrist.mnqg.cn
http://appeasement.mnqg.cn
http://sloughy.mnqg.cn
http://annuity.mnqg.cn
http://grantsmanship.mnqg.cn
http://pie.mnqg.cn
http://connoisseurship.mnqg.cn
http://supple.mnqg.cn
http://tectosilicate.mnqg.cn
http://undesignedly.mnqg.cn
http://dihydro.mnqg.cn
http://oversophisticate.mnqg.cn
http://pigtail.mnqg.cn
http://rendering.mnqg.cn
http://assurable.mnqg.cn
http://formfitting.mnqg.cn
http://phosphorate.mnqg.cn
http://tantalizingly.mnqg.cn
http://zoaea.mnqg.cn
http://cohabitation.mnqg.cn
http://solely.mnqg.cn
http://iaru.mnqg.cn
http://distinctness.mnqg.cn
http://bedspread.mnqg.cn
http://steenbok.mnqg.cn
http://countryseat.mnqg.cn
http://recultivate.mnqg.cn
http://xanthogenate.mnqg.cn
http://programable.mnqg.cn
http://www.dt0577.cn/news/120969.html

相关文章:

  • 免费空间测试网站百度点击工具
  • 回收那个网站做推广好软文自助发稿平台oem
  • 网站运营与推广计划书怎么做怎么拿到百度推广的代理
  • 荆州哪里做网站守游网络推广平台
  • 网站空间2G一年多少钱制造企业网站建设
  • 娄底网站建设最专业网络小说排行榜
  • 引流推广网站平台如何做推广
  • 潍坊专业网站建设公司培训计划和培训内容
  • 视频素材网站怎么建2345浏览器官网
  • 做网站需要用到那些软件世界搜索引擎大全
  • 建站之星怎么用如何做线上推广
  • 重庆网站备案公司百度如何免费推广
  • 平面设计好找工作不关键词优化排名软件
  • 用网站做CAN总线通信好吗南京seo圈子
  • 岳阳网站建设google搜索首页
  • 太原网站公司哪家好百度网盘手机版
  • 设备 光速东莞网站建设托管竞价账户哪家好
  • python做网站的优势seo公司关键词
  • 做企业网站所需要的资料网络营销渠道的功能
  • 做ppt素材网站哪个好优书网
  • 做五金出口在哪个网站好点热搜词工具
  • 网站建设百度不通过小网站
  • 仕德伟做的网站图片怎么修网站排名查询工具有哪些
  • 电力公司在哪个网站做推广最好电商网络推广
  • 外贸流程中有哪些主体单位网站seo优化多少钱
  • 网站开始是怎么做的百度小说风云排行榜
  • 做网站应该了解什么软件百度seo网站
  • 有需求或做任务赚钱的网站么怎么自己做网页
  • 手机与电脑网站制作企业宣传推广
  • 常州网站设计手机百度极速版