我正在用Keras构建一个语言模型,我想用困惑作为我的损失函数,但是当我试图用我的损失函数编译我的模型时,我得到了一个值错误,说损失函数是未知的。
我的损失函数如下:
def perplexity_loss(y_true, y_pred):
"""
The perplexity metric. Why isn't this part of Keras yet?!
https://stackoverflow.com/questions/41881308/how-to-calculate-perplexity-of-rnn-in-tensor
因此,我试图训练我的LSTM网络语言模型,并使用一个困惑函数作为我的损失函数,但是我得到了以下错误:
ValueError: An operation has `None` for gradient. Please make sure that all of your ops have a gradient defined (i.e. are differentiable). Common ops without gradient: K.argmax, K.round, K.eval.
我的损失函数如下:
from keras import backend as K
def perplexit
在我的代码中,我只想创建包含[tsne_results_50,tsne_results_30,tsne_results_50,tsne_results_100]的tsne_results列表。但我不能,因为上面写的是Cannot assign to literal。我怎么才能修复它? perplexity_values=[5,30,50,100]
tsne_results=[]
for value in perplexity_values:
tsne = TSNE(n_components=2, verbose=1, perplexity=value, n_iter=250)
f
我正在尝试为我的LSTM语言模型实现一个困惑损失函数。然而,我得到了以下错误:
InvalidArgumentError: logits and labels must have the same first dimension, got logits shape [32,3345] and labels shape [107040]
[[{{node loss_9/dense_10_loss/perplexity/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits}}]]
现在,我认为解决这
我将为LDA计算文本数据的复杂性和连贯性。我运行以下代码
# Compute Perplexity
print('\nPerplexity: ', lda_model.log_perplexity(corpus)) # a measure of how good the model is. lower the better.
# Compute Coherence Score
coherence_model_lda = CoherenceModel(model=lda_model, texts=data_lemmatized, dictionary=id2word, cohe
正如我经常提到的,我正在使用text2vec处理23万个文档。我正在尝试使用perplexity为我的文档术语矩阵找到最佳主题编号。当我一个接一个地使用它时,它工作得很好,但是当我尝试使用一个循环来获得从2到25的范围时,它不能工作,我不知道为什么,有人能告诉我哪里出了问题吗?
##Using perplexity for hold out set
t1 <- Sys.time()
perplex <- c()
for (i in 2:25){
set.seed(17)
lda_model <- LDA$new(n_topics = i)
doc_to
我试图使用python中的日志困惑来确定我的LDA模型的最佳主题数量。也就是说,我正在绘制一系列主题的日志困惑,并确定最低限度的困惑。然而,我得到的图对于日志困惑有负值,当它应该有0到1之间的正值时。
#calculating the log perplexity per word as obtained by gensim code
##https://radimrehurek.com/gensim/models/atmodel.html
#parameters: pass in trained corpus
#return: graph of perplexity per word fo
我收到一个NGramModel错误...请告诉我我可能出错的地方。
Traceback (most recent call last):
File "ai7.py", line 87, in <module>
tt=NgramModel(1, tText, estimator)
NameError: name 'NgramModel' is not defined
我的目标是计算文本的困惑程度。
f_in = open("science.txt", 'r');
ln = f_in.read()
w
我有一个很大的文件(下面是一小组数据),如下所示,我想画一个PCA,我可以使用PCA函数来绘制PCA,但它看起来有点混乱,因为我有200列,所以我认为t-SNE或UMAP可能更好,但我不能使用它们绘制。
我想在图中显示列(列名)之间的关系和聚类。事实上,我从不同的研究中收集了A,B和...data,我喜欢检查它们之间是否存在批量效应。
如果有人能帮助我,我将不胜感激!
DF:
A B C D
1:540450-541070 0.12495878 0.715
我正在运行一个程序,使用t-sne将MNIST数据的维度从784维减少到2维。 该程序需要很长时间才能完成,我想使用tqdm进度条来跟踪进度。 我想知道如何使用t-sne函数添加tqdm进度条。tqdm可以很好地处理循环。 我不知道如何使用它的功能。 # TSNE
from sklearn.manifold import TSNE
# Picking the top 1000 points as TSNE takes a lot of time for 15K points
data_1000 = standardized_data[0:30000,:]
labels_1000 = lab
我正在建立一个应用程序的原型,我需要一个语言模型来计算一些生成的句子的困惑。
在python中有任何经过训练的语言模型我可以很容易地使用吗?一些简单的事情,比如
model = LanguageModel('en')
p1 = model.perplexity('This is a well constructed sentence')
p2 = model.perplexity('Bunny lamp robert junior pancake')
assert p1 < p2
我看过一些框架,但找不到我想要的。我知道我可以用这样的方法:
我正在尝试运行下面的代码来生成一个JSON文件,并使用它构建一个带有一组图像的t。然而,我在Keras和机器学习方面的经验有限,我无法在下面运行代码并得到错误: AttributeError:‘张量’对象没有属性'_keras_shape‘
import argparse
import sys
import numpy as np
import json
import os
from os.path import isfile, join
import keras
from keras.preprocessing import image
from keras.applications
为了把我的问题放在上下文中,我想训练和测试/比较几个(神经)语言模型。为了专注于模型而不是数据准备,我选择使用来自nltk的Brown语料库,并训练nltk提供的Ngram模型作为基线(与其他LM进行比较)。
所以我的第一个问题实际上是关于nltk的Ngram模型的一个行为,我觉得可疑。由于代码相当简短,我将其粘贴到以下位置:
import nltk
print "... build"
brown = nltk.corpus.brown
corpus = [word.lower() for word in brown.words()]
# Train on 95% f th
我一直在TenserFlow教程中遍历RNN代码:
原始RNN代码如下:
我把训练过的RNN模型保存为“列车模型”。
if FLAGS.save_path:
print("Saving model to %s." % FLAGS.save_path)
sv.saver.save(session, FLAGS.save_path, global_step=sv.global_step)
现在,我试图恢复保存的模型,并通过以下方法运行附加测试
with tf.name_scope("Test"):
test_input = PTBInput(
我已经在Spark2.0中创建了一个用于进行LDA的PipelineModel (通过PySpark API):
def create_lda_pipeline(minTokenLength=1, minDF=1, minTF=1, numTopics=10, seed=42, pattern='[\W]+'):
"""
Create a pipeline for running an LDA model on a corpus. This function does not need data and will not actually
使用sklearn的TSNE 和mahalanobis度量,我得到了以下错误
from sklearn.manifold import TSNE
tsne = TSNE( verbose=1, perplexity=40, n_iter=250,learning_rate=50, random_state=0,metric='mahalanobis')
pt=data.sample(frac=0.1).values
tsne_results = tsne.fit_transform(pt)
ValueError: Must provide either V or V
我正在尝试将一些CIFAR10图像数据处理成图像瓦片,以便在黑色画布上使用PIL绘图。在从经过训练的模型中提取特征时,我已经成功地做到了这一点,但在使用Image.fromarray时,我一直在使用IndexError: Tuple Index out of range。 我的特征被塑造成形状(10000,3072)的测试数据。数据为32x32x3图像。我加载了cifar10数据,然后扁平化了数据,但一直收到这个错误。 这是我的代码。其中一些是从https://medium.com/@pslinge144/representation-learning-cifar-10-23b0d9833c
我尝试使用sklearn的LDA模型找到最优的主题数量。为此,我通过引用上的代码来计算困惑。
但是当我增加主题的数量时,困惑总是不合理地增加。是我在实现上错了,还是仅仅是它给出了正确的值?
from __future__ import print_function
from time import time
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.decomposition import NMF, LatentDirichletAllocation
n_