小编ZEW*_*CHU的帖子

从SpaCy删除范围内的单词?

我正在解析Spacy的句子,如下所示:

import spacy
nlp = spacy.load("en")
span = nlp("This is some text.")
Run Code Online (Sandbox Code Playgroud)

我想知道是否有一种方法可以删除跨度中的单词,同时仍然保持其余单词的格式像句子一样。如

del span[3]
Run Code Online (Sandbox Code Playgroud)

这可能会产生一个句子

这是一些。

如果没有SpaCy的其他一些方法也可以达到相同的效果,那也很好。

nlp python-3.x spacy

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

如何在numpy中收集特定索引的元素?

我想在指定轴上收集指定索引的元素,如下所示。

x = [[1,2,3], [4,5,6]]
index = [[2,1], [0, 1]]
x[:, index] = [[3, 2], [4, 5]]
Run Code Online (Sandbox Code Playgroud)

这本质上是 pytorch 中的收集操作,但如您所知,这在 numpy 中是无法通过这种方式实现的。我想知道numpy中是否有这样的“收集”操作?

numpy

5
推荐指数
3
解决办法
5638
查看次数

使用以下tensorflow代码占用所有GPU内存?

我正在使用https://github.com/chiphuyen/stanford-tensorflow-tutorials/blob/master/examples/04_word2vec_no_frills.py中的代码试验word2vec

但是,它很容易耗尽我所有的GPU内存,不知道为什么?

with tf.name_scope('data'):
    center_words = tf.placeholder(tf.int32, shape=[BATCH_SIZE], name='center_words')
    target_words = tf.placeholder(tf.int32, shape=[BATCH_SIZE, 1], name='target_words')

with tf.name_scope("embedding_matrix"):
    embed_matrix = tf.Variable(tf.random_uniform([VOCAB_SIZE, EMBED_SIZE], -1.0, 1.0), name="embed_matrix")

with tf.name_scope("loss"):
    embed = tf.nn.embedding_lookup(embed_matrix, center_words, name="embed")

    nce_weight = tf.Variable(tf.truncated_normal([VOCAB_SIZE, EMBED_SIZE], stddev=1.0/(EMBED_SIZE ** 0.5)), name="nce_weight")
    nce_bias = tf.Variable(tf.zeros([VOCAB_SIZE]), name="nce_bias")


    loss = tf.reduce_mean(tf.nn.nce_loss(weights=nce_weight, biases=nce_bias, labels=target_words, inputs=embed, num_sampled=NUM_SAMPLED, num_classes=VOCAB_SIZE), name="loss")


optimizer = tf.train.GradientDescentOptimizer(LEARNING_RATE).minimize(loss)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    total_loss = 0.0 # we use this to calculate the average loss in the last SKIP_STEP steps
    writer …
Run Code Online (Sandbox Code Playgroud)

memory gpu tensorflow

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

标签 统计

gpu ×1

memory ×1

nlp ×1

numpy ×1

python-3.x ×1

spacy ×1

tensorflow ×1