小编Fel*_*lix的帖子

检索句子的注意力权重?最专注的句子是零向量

我有一个文档分类任务,将文档分类为好(1)或坏(0),并且我对每个文档使用一些句子嵌入来相应地对文档进行分类。

我喜欢做的是检索每个文档的注意力分数,以获得最“相关”的句子(即那些具有高注意力分数的句子)

我将每个文档填充到相同的长度(即每个文档 1000 个句子)。所以我的 5000 个文档的张量看起来像这样X = np.ones(shape=(5000, 1000, 200))(5000 个文档,每个文档都有 1000 个句子向量序列,每个句子向量由 200 个特征组成)。

我的网络如下所示:

no_sentences_per_doc = 1000
sentence_embedding = 200

sequence_input  = Input(shape=(no_sentences_per_doc, sentence_embedding))
gru_layer = Bidirectional(GRU(50,
                          return_sequences=True
                          ))(sequence_input)
sent_dense = Dense(100, activation='relu', name='sent_dense')(gru_layer)  
sent_att,sent_coeffs = AttentionLayer(100,return_coefficients=True, name='sent_attention')(sent_dense)
preds = Dense(1, activation='sigmoid',name='output')(sent_att)  
model = Model(sequence_input, preds)

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=[TruePositives(name='true_positives'),
                      TrueNegatives(name='true_negatives'),
                      FalseNegatives(name='false_negatives'),
                      FalsePositives(name='false_positives')
                      ])

history = model.fit(X, y, validation_data=(x_val, y_val), epochs=10, batch_size=32)
Run Code Online (Sandbox Code Playgroud)

训练后,我检索了注意力分数,如下所示:

sent_att_weights = Model(inputs=sequence_input,outputs=sent_coeffs)

## load a single sample
## from file with …
Run Code Online (Sandbox Code Playgroud)

python nlp keras tensorflow attention-model

5
推荐指数
0
解决办法
402
查看次数

AttributeError:“列表”对象使用Selenium和Python没有属性“单击”

我想在默认设置为“季度”的页面上单击“年度”按钮。有两个基本上相同的链接,除了一个链接,data-ptype="Annual"所以我尝试复制xpath来单击按钮(也尝试了其他选项,但没有一个起作用)。

但是,我得到了AttributeError: 'list' object has no attribute 'click'。我读过很多类似的文章,但无法解决我的问题..因此,我认为必须调用/单击/执行javascript事件以某种方式不同。

from selenium import webdriver
link = 'https://www.investing.com/equities/apple-computer-inc-balance-sheet'

driver = webdriver.Firefox()
driver.get(link)
elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()
Run Code Online (Sandbox Code Playgroud)

html如下:

<a class="newBtn toggleButton LightGray" href="javascript:void(0);" data-type="rf-type-button" data-ptype="Annual" data-pid="6408" data-rtype="BAL">..</a>
Run Code Online (Sandbox Code Playgroud)

javascript python selenium webdriver selenium-webdriver

4
推荐指数
2
解决办法
1592
查看次数