小编bri*_*akh的帖子

仅从格式为 .tex 的 arXiv 文章中提取正文文本

我的数据集由作为 .tex 文件的 arXiv 天体物理学文章组成,我只需要从文章正文中提取文本,而不是从文章的任何其他部分(例如表格、图表、摘要、标题、脚注、致谢、引文等) .)

我一直在尝试使用 Python3 和tex2py,但我正在努力获得一个干净的语料库,因为文件在标签上有所不同,并且文本在标签之间被分解。

我附上了一个 SSCCE、几个示例 Latex 文件及其 pdf,以及解析的语料库。语料库显示了我的挣扎:节和小节没有按顺序提取,在某些标签处文本中断,并且包含了一些表格和图形。

代码:

import os
from tex2py import tex2py

corpus = open('corpus2.tex', 'a')

def parseFiles():
    """
    Parses downloaded document .tex files for word content.
    We are only interested in the article body, defined by /section tags.
    """

    for file in os.listdir("latex"):
        if file.endswith('.tex'):
            print('\nChecking ' + file + '...')
            with open("latex/" + file) as f:
                try:
                    toc = tex2py(f) # toc = tree of contents
                    # …
Run Code Online (Sandbox Code Playgroud)

python latex nlp extract tex

6
推荐指数
1
解决办法
826
查看次数

如何使用 BERT 预测空字符串的概率

假设我们有一个这样的模板句子:

  • “____房子是我们见面的地方。”

我们有一个形容词列表来填补空白,例如:

  • “黄色的”
  • “大的”
  • ””

请注意,其中之一是空字符串。

目标是比较在给定句子上下文的情况下选择最有可能描述“房子”的单词的概率。如果更有可能什么都没有,也应该考虑到这一点。

我们可以预测每个单词填空的概率,但是我们如何预测没有形容词来描述“房子”的可能性呢?

预测一个单词的概率:

from transformers import BertTokenizer, BertForMaskedLM
import torch
from torch.nn import functional as F

# Load BERT tokenizer and pre-trained model
tokenizer = BertTokenizer.from_pretrained('bert-large-uncased')
model = BertForMaskedLM.from_pretrained('bert-large-uncased', return_dict=True)

targets = ["yellow", "large"]
sentence = "The [MASK] house is our meeting place."

# Using BERT, compute probability over its entire vocabulary, returning logits
input = tokenizer.encode_plus(sentence, return_tensors = "pt") 
mask_index = torch.where(input["input_ids"][0] == tokenizer.mask_token_id)[0] 
with torch.no_grad():
    output = model(**input) 

# …
Run Code Online (Sandbox Code Playgroud)

python nlp bert-language-model huggingface-transformers

6
推荐指数
1
解决办法
888
查看次数

从Git重新恢复 - 在Eclipse中使用硬件

我不小心对我的git repo做了些什么,我不知道我是否可以保存我的项目......

我做了一些改变.然后我想删除我的最后一次提交,以便我可以改为进行新的提交.我忘了做git stash.因此,当我跑步时,git reset --hard [second-to-last commit]它删除了我所做的一切.这是愚蠢的,但有什么我可以做的来拯救我最近的工作?

我正在使用Eclipse IDE.

eclipse git commit git-reset

5
推荐指数
1
解决办法
371
查看次数

使用 dbt 中的星形宏获取列名称和类型

使用星形宏,除了列名之外,是否还有办法获取列数据类型(布尔值、数值等)?

例如,此查询使用星号宏从引用表中收集列名,将其保存为数组变量column_names,然后循环该数组并将 max 函数应用于所有列。

{% set column_names = star(
    from=ref_table,
    except=["a", "b", "c"],
    as_list=True)
%}

select 
    date_trunc('week', day) as week,
    name,

    {%- for col in column_names %}  
    max({{ col|lower }}) as {{ col | lower }}{%- if not loop.last %},{{ '\n  ' }}{% endif %}
    {%- endfor %}

from {{ ref('my_table_name') }}    
group by 1, 2
Run Code Online (Sandbox Code Playgroud)

我想有条件地将 max 函数仅应用于布尔列。

这可能看起来像

{%- for col in column_names %}  
    {% if is_boolean(col) %}  
    max({{ col|lower }}) as {{ col | lower …
Run Code Online (Sandbox Code Playgroud)

sql dbt

5
推荐指数
1
解决办法
1万
查看次数

尽管安装了证书,但由于 sun.security.validator.ValidatorException 导致 Gradle 构建失败

我正在尝试根据他们的说明运行lenskit-hello。当我运行时./gradlew build,我收到错误

(base) Briennas-MBP:lenskit-hello-master briennakh$ ./gradlew build
:compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not resolve org.lenskit:lenskit-all:3.0-M3.
  Required by:
      :lenskit-hello-master 4.50.57 AM:unspecified
   > Could not resolve org.lenskit:lenskit-all:3.0-M3.
      > Could not get resource 'https://repo1.maven.org/maven2/org/lenskit/lenskit-all/3.0-M3/lenskit-all-3.0-M3.pom'.
         > Could not GET 'https://repo1.maven.org/maven2/org/lenskit/lenskit-all/3.0-M3/lenskit-all-3.0-M3.pom'.
            > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
   > Could not resolve org.lenskit:lenskit-all:3.0-M3.
      > Could not …
Run Code Online (Sandbox Code Playgroud)

java macos ssl-certificate gradle java-8

4
推荐指数
1
解决办法
5237
查看次数

如何更改 R 华夫饼图中“瓷砖灌浆”的颜色以匹配背景

我正在尝试制作一个华夫饼图来使用黑暗模式。这涉及更改背景颜色和瓷砖灌浆的颜色。我不知道如何做瓷砖灌浆。

我无法执行任何正常操作来更改颜色:

counts <- c(a = 701, b = 1094, c = 1756)
waffle(counts, 
   rows=50,
   size=0.75,
   legend_pos="bottom") + theme(legend.key.size=unit(3, "mm"),
                                rect=element_rect(fill='black',
                                                  color='black'),
                                plot.background=element_rect(fill='black'),
                                strip.background = element_rect(colour=NA, fill=NA),
                                panel.background=element_rect(fill='black', color='black'))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

有一个拉取请求可以执行此操作,但发出请求的人删除了它。似乎颜色被设置为每个图块上的边距颜色,因为如果将 waffle 函数参数增加到sizesize=0则不会得到图块灌浆:

在此输入图像描述

如何使瓷砖填缝剂的颜色与背景一样黑色?

r ggplot2 waffle-chart

4
推荐指数
1
解决办法
414
查看次数

如何将未经检查的强制转换为 ArrayList&lt;Vehicle&gt;

对于一个类,我被分配Vehicle使用 ObjectInputStream ( in)编写代码以读取类的对象。对象存储在名为 的 ArrayList 中orders

SSCE:

// Read all orders
Object obj = in.readObject();
orders = (ArrayList<Vehicle>) obj;
Run Code Online (Sandbox Code Playgroud)

但是,编译器抱怨:

MacBook:Homework Brienna$ javac Orders.java -Xlint:unchecked
Orders.java:152: warning: [unchecked] unchecked cast
                    orders = (ArrayList<Vehicle>) in.readObject();
                                                                ^
  required: ArrayList<Vehicle>
  found:    Object
1 warning
Run Code Online (Sandbox Code Playgroud)

我总是尝试改进我的代码,而不是忽略或抑制警告。在这种情况下,我想出了一个解决方案,但我试图了解它为什么有效,以及是否有更好的解决方案。

此更新停止警告:

// Read all orders, casting each order individually
Object obj = in.readObject();
ArrayList ar = (ArrayList) obj;
for (Object x : ar) {
    orders.add((Vehicle) x);
}
Run Code Online (Sandbox Code Playgroud)

根据我从我阅读的内容中了解到的内容,它可以工作,因为(ArrayList<Vehicle>) obj如果不是所有元素都是Vehicle …

java casting arraylist compiler-warnings unchecked-cast

3
推荐指数
1
解决办法
3463
查看次数

找不到函数 plot.gam

我正在阅读“R 中的应用程序统计学习简介”(ISLR),我被困在第 295 页上的一部分,即广义加性模型实验室。当我运行以下代码时,出现错误Error in plot.gam(gam1, se = TRUE, col = "red") : could not find function "plot.gam"

library(ISLR)
gam1 = lm(wage ~ ns(year, 4) + ns(age, 5) + education, data=Wage)
par(mfrow=c(1,3))
plot.gam(gam1, se=TRUE, col="red")
Run Code Online (Sandbox Code Playgroud)

书上说plot.gam应该是通用plot函数的一部分,为什么R找不到呢?我应该做一些不同的事情吗?我尝试使用install.packages('plot', repos='http://cran.us.r-project.org').

这让我感到困惑,因为这本书是这样说的:

通用的plot() 函数识别出gam2 是gam 类的对象,并调用了适当的plot.gam() 方法。方便,即使plot.gam() gam1 不是gam 类而是lm 类,我们仍然可以使用plot.gam () 在上面。图 7.11 是使用以下表达式生成的:

plot.gam(gam1, se=TRUE, col="red")

syntax plot packages r gam

3
推荐指数
1
解决办法
2289
查看次数

将锯齿状数组转换为 Pandas 数据框

我正在尝试获得一个看起来像这样的锯齿状 2D 列表

l = [
    [(1, 0.8656769), (2, 0.08902887), (5, 0.040293545)],
    [(1, 0.5918752), (2, 0.04440181), (4, 0.05204634), (5, 0.3066661)],
    [(1, 0.26327166), (2, 0.26078925), (4, 0.24160784), (5, 0.22958432)],
    [(2, 0.92498404), (5, 0.065140516)],
    [(1, 0.9882947)],
    [(0, 0.23412614), (1, 0.031903207), (2, 0.03044448), (3, 0.6480669), (4, 0.053342175)],
    [(0, 0.056099385), (3, 0.9084766), (5, 0.031809118)],
    [(2, 0.39833495), (4, 0.52058107), (5, 0.077259734)],
    [(0, 0.46812743), (1, 0.10643007), (3, 0.15962379), (4, 0.017917762), (5, 0.24552101)],
    [(0, 0.2556301), (1, 0.7391994)]
]
Run Code Online (Sandbox Code Playgroud)

变成一个如下所示的数据框:

在此处输入图片说明

在 中l,每一行可能包含也可能不包含所有列。每个元组的结构如下(column_label, cell_value)。如果该行缺少一列,则其值应在数据框中设置为 0。 …

python jagged-arrays pandas

3
推荐指数
1
解决办法
316
查看次数

为什么我的下载进度条多次触发同一事件?

我正在练习Swing,当用户按下"开始下载"按钮时,我编写了一个下载进度条来下载图像.下载工作.问题是在我的终端中,我可以看到同一个事件(propertyChange)被多次触发,每次后续下载的次数都会增加.我用检查点调试了我的代码,但我仍然不确定为什么会发生这种情况.

更具体地说,在我的终端我看到了类似的东西

...100% completed 
...100% completed 
...100% completed 
...100% completed 
...100% completed 
...100% completed 
...100% completed
Run Code Online (Sandbox Code Playgroud)

当我希望看到"...... 100%完成"只有一次.每次下载时,显示的"... 100%已完成"的数量会累积.我不确定这是否会影响我的下载性能,但我想知道为什么会发生这种情况.

ProgressBar.java:

package download_progress_bar;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ProgressBar {
    private JFrame frame;
    private JPanel gui;
    private JButton button;
    private JProgressBar progressBar;

    public ProgressBar() {
        customizeFrame();
        createMainPanel();
        createProgressBar();
        createButton();
        addComponentsToFrame();
        frame.setVisible(true);
    }

    private void customizeFrame() {
        // Set the look and feel to the cross-platform look and feel
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) { …
Run Code Online (Sandbox Code Playgroud)

java swing swingworker jprogressbar

1
推荐指数
1
解决办法
108
查看次数

尽管已同步,Vector仍会抛出ConcurrentModificationException

我有一个由多个线程操作的ArrayList,由于ArrayList未同步,因此无法正常工作.我按照教授的指示将列表切换为Vector.向量是同步的,但我有与同步相关的异常抛出.

为什么会发生这种情况,如何在代码中避免并发异常?我不想只是玩游戏直到有效,我想做最好的事情.谢谢!

例外:

Exception in thread "Thread-3" java.util.ConcurrentModificationException
    at java.util.Vector$Itr.checkForComodification(Vector.java:1184)
    at java.util.Vector$Itr.next(Vector.java:1137)
    at BytePe4D$ReadInts.run(BytePe4D.java:64)
Run Code Online (Sandbox Code Playgroud)

码:

import java.io.*;
import java.util.Vector;

public class BytePe4D {
    private Vector<Integer> numbers;

    public static void main(String[] args) {
        new BytePe4D();
    }

    public BytePe4D() {
        // Create ArrayList and reset sum
        numbers = new Vector<Integer>();

        // Call addInts 8 times, with filenames integer1.dat through integer8.dat
        for (int i = 1; i <= 8; i++) {
            File file = new File("PE Data/integer" + i + ".dat");
            ReadInts thread …
Run Code Online (Sandbox Code Playgroud)

java multithreading synchronization vector concurrentmodification

1
推荐指数
1
解决办法
579
查看次数

为什么这个简单的 LISP 函数会抛出错误?

我将这个函数从一个更大的脚本中分离出来,并通过https://www.jdoodle.com/execute-clisp-online/运行它。即使抛出了一个错误,它似乎也遵循 LISP 的规则,除非我遗漏了一些明显的东西。

(defun cannibals-can-eat (state start-state)
    (let ((left-bank-missionaries 2)
         (left-bank-cannibals 5)
         (right-bank-missionaries (- 3 left-bank-missionaries))
         (right-bank-cannibals (- 2 left-bank-cannibals)))

         (if (or (> left-bank-cannibals left-bank-missionaries)
                 (> right-bank-cannibals right-bank-missionaries))
             t
             nil)))
Run Code Online (Sandbox Code Playgroud)

错误有时是The variable LEFT-BANK-MISSIONARIES is unbound.unmatched close parenthesissyntax error near unexpected token('`。使用此版本的函数,错误是后者。

lisp clisp common-lisp syntax-error

1
推荐指数
1
解决办法
86
查看次数

如何创建基于 y 值的梯度阶梯图?

在 Python matplotlib 中,如何获得折线图或阶梯图中的线以显示基于 y 值的梯度?

示例图(在 Tableau 中制作):

在此输入图像描述

带有根据 x 值改变梯度的线的阶梯图代码,改编自此答案

fig, ax = plt.subplots(figsize=(10, 4))
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
y = [2, 3, 9, 10, 2, 9, 0, 1, 9, 1, -8]
T = np.linspace(0,1,np.size(x))**2
s = 1
for i in range(0, len(x)-s, s):
    ax.step(x[i:i+s+1], y[i:i+s+1],  marker='.', color=(0.0,0.5,T[i]))
ax.tick_params(axis='both', colors='lightgray', labelsize=8)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python linear-gradients seaborn

0
推荐指数
1
解决办法
809
查看次数