当我按照说明嵌入IPython 0.10时,某些列表推导无法正常工作.我的全局命名空间发生了什么?
$ python
>>> import IPython.Shell
>>> IPython.Shell.IPShellEmbed()()
In [1]: def bar(): pass
...:
In [2]: list(bar() for i in range(10))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/<ipython console>
/tmp/<ipython console> in <generator expression>([outmost-iterable])
NameError: global name 'bar' is not defined
Run Code Online (Sandbox Code Playgroud) 任何人都了解犀牛javascript上下文?我找不到任何有用的文档.我的主要问题是Context.exit()(真的应该是cx.exit())根据我的理解退出与当前线程相关的上下文?这是否意味着我需要跟踪哪个线程的作用?
主线程:
Context cx;
cx.evaluateReader( ... ) // load some function
start thread 2
Run Code Online (Sandbox Code Playgroud)
线程2:
Object o= scope.get("methodname", scope);
((Function)o).call( ... )
Run Code Online (Sandbox Code Playgroud)
我不打算做多线程但是如果不同的设置来自不同的线程怎么办?
在AS3中,您可以将图形嵌入到Class变量中:
[Embed(source="MenuAssets.swf", symbol="topSquare")]
public var TopMenuItem:Class;
Run Code Online (Sandbox Code Playgroud)
我在这个网站项目中有数百个资产,所以我想将资产嵌入数组中以便快速访问.
我可以这样做吗?它没有编译所以我想知道它是否可能.
public var MenuAssets:Array = [
[Embed(source="MenuAssets.swf", symbol="topSquare")],
[Embed(source="MenuAssets.swf", symbol="botSquare")],
[Embed(source="MenuAssets.swf", symbol="leftSquare")],
[Embed(source="MenuAssets.swf", symbol="rightSquare")],
]
Run Code Online (Sandbox Code Playgroud) 该应用程序在 Linux、Windows、Macintosh 中运行。
另外,如果是,需要多少努力?
如果我有带有嵌入式 Python 函数的 C++ 代码,即它使用 Python 的 C API 来调用 Python 的解释器,我怎样才能让 Python 异常冒泡到 C++ 级别?
注意:这不是相反的问题(关于将 C++ 扩展异常传播到 Python 解释器)。
我们尝试过使用tf.nn.embedding_lookup它并且有效.但它需要密集的输入数据,现在我们需要tf.nn.embedding_lookup_sparse稀疏输入.
我写了以下代码,但得到了一些错误.
import tensorflow as tf
import numpy as np
example1 = tf.SparseTensor(indices=[[4], [7]], values=[1, 1], shape=[10])
example2 = tf.SparseTensor(indices=[[3], [6], [9]], values=[1, 1, 1], shape=[10])
vocabulary_size = 10
embedding_size = 1
var = np.array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0])
#embeddings = tf.Variable(tf.ones([vocabulary_size, embedding_size]))
embeddings = tf.Variable(var)
embed = tf.nn.embedding_lookup_sparse(embeddings, example2, None)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print(sess.run(embed))
Run Code Online (Sandbox Code Playgroud)
错误日志如下所示.
现在我不知道如何正确修复和使用此方法.任何评论都可以表示赞赏.
潜入后safe_embedding_lookup_sparse的单元测试,我更困惑,为什么我如果给稀疏的权重,尤其是为什么我们得到的东西像得到这个结果embedding_weights[0][3],其中3在代码中没有出现以上.
我使用 Keras 并尝试将两个不同的层连接成一个向量(向量的第一个值是第一层的值,另一部分是第二层的值)。其中一层是密集层,另一层是嵌入层。
我知道如何合并两个嵌入层或两个密集层,但我不知道如何合并一个嵌入层和一个密集层(维度问题)。
一个简单的例子是这样的:
L_branch = Sequential()
L_branch.add(Dense(10, input_shape = (4,) , activation = 'relu'))
L_branch.add(BatchNormalization())
R_branch = Sequential()
R_branch.add(Embedding(1000, 64, input_length=5))
final_branch.add(Merge([L_branch, R_branch], mode = 'concat'))
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为您无法合并具有不同维度的图层。
PS:对不起,英语不是我的母语,我希望你能理解我的问题。
此致。
我正在基于Keras的seq2seq创建一个生成的聊天机器人.我使用了以下网站的代码:https://machinelearningmastery.com/develop-encoder-decoder-model-sequence-sequence-prediction-keras/
我的模型看起来像这样:
# define training encoder
encoder_inputs = Input(shape=(None, n_input))
encoder = LSTM(n_units, return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
encoder_states = [state_h, state_c]
# define training decoder
decoder_inputs = Input(shape=(None, n_output))
decoder_lstm = LSTM(n_units, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states)
decoder_dense = Dense(n_output, activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)
# define inference encoder
encoder_model = Model(encoder_inputs, encoder_states)
# define inference decoder
decoder_state_input_h = Input(shape=(n_units,))
decoder_state_input_c = Input(shape=(n_units,))
decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
decoder_outputs, …Run Code Online (Sandbox Code Playgroud) 使用预训练嵌入,我们可以将它们指定为 keras 嵌入层中的权重。要使用多个嵌入,指定多个嵌入层是否合适?IE
embedding_layer1 = Embedding(len(word_index) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix_1],
input_length=MAX_SEQUENCE_LENGTH,
trainable=False)
embedding_layer2 = Embedding(len(word_index) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix_2],
input_length=MAX_SEQUENCE_LENGTH,
trainable=False)
model.add(embedding_layer1)
model.add(embedding_layer2)
Run Code Online (Sandbox Code Playgroud)
这建议将它们总结起来并将它们表示为一个层,这不是我所追求的。
我正在尝试了解如何在 Keras 中创建具有多个嵌入层和其他输入的模型。这是我的模型的结构方式(E=嵌入层,[....]=输入层):
E E [V V V]
\ | /
\ | /
Dense
|
Dense
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
model_a = Sequential()
model_a.add(Embedding(...))
model_b = Sequential()
model_b.add(Embedding(...))
model_c = Sequential()
model_c.add(Embedding(...))
model_values = Sequential()
model_values.add(Input(...))
classification_model = Sequential()
classification_layers = [
Concatenate([model_a,model_b,model_c, model_values]),
Dense(...),
Dense(...),
Dense(2, activation='softmax')
]
for layer in classification_layers:
classification_model.add(layer)
classification_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
classification_model.fit(train_data,one_hot_labels, epochs=1, validation_split=0.2)
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
ValueError: A `Concatenate` layer should be called on a list of at least 2 inputs
Run Code Online (Sandbox Code Playgroud)
我不知道我在这里做错了什么。这是错误日志的更多细节:
---------------------------------------------------------------------------
ValueError Traceback (most recent …Run Code Online (Sandbox Code Playgroud)