eliorc / medium Goto Github PK
View Code? Open in Web Editor NEWCode related to blog posts on my Medium page
Code related to blog posts on my Medium page
I got an error here...
plt.plot(malstm_trained.history['acc'])
plt.plot(malstm_trained.history['val_acc'])
KeyError Traceback (most recent call last)
in
1 # Plot accuracy
----> 2 plt.plot(malstm_trained.history['acc'])
3 plt.plot(malstm_trained.history['val_acc'])
4 plt.title('Model Accuracy')
5 plt.ylabel('Accuracy')KeyError: 'acc'
Hi,
I should get the GRU layer output vector for use other distance method such as cosine. My code as follows:
left_input = Input(shape=(input_shape,), dtype='int32', name="left_input_layer") right_input = Input(shape=(input_shape,), dtype='int32', name="right_input_layer") embedding_layer = Embedding(max_features+1, embed_dims, name="embedding_layer") encoded_left = embedding_layer(left_input) encoded_right = embedding_layer(right_input) left_output = GRU(128, name="rnn_layer_left")(encoded_left) right_output = GRU(128, name="rnn_layer_right")(encoded_right) malstm_distance = Lambda(function=lambda x: exponent_neg_manhattan_distance(x[0], x[1]), output_shape=lambda x: (x[0][0], 1))([left_output, right_output])
and get GRU layer output code:
intermediate_layer_model = Model(inputs=model.input, outputs=model.get_layer(layer_name).output) intermediate_output = intermediate_layer_model.predict([idx1, idx2])
However, the different sentence gets the same vector, but when I predict the probability it's OK. Can you give me some suggestions?
`max_seq_length = max(train_df.question1.map(lambda x: len(x)).max(),
train_df.question2.map(lambda x: len(x)).max(),
test_df.question1.map(lambda x: len(x)).max(),
test_df.question2.map(lambda x: len(x)).max())
validation_size = 40000
training_size = len(train_df) - validation_size
X = train_df[questions_cols]
Y = train_df['is_duplicate']
X_train, X_validation, Y_train, Y_validation = train_test_split(X, Y, test_size=validation_size)
X_train = {'left': X_train.question1, 'right': X_train.question2}
X_validation = {'left': X_validation.question1, 'right': X_validation.question2}
X_test = {'left': test_df.question1, 'right': test_df.question2}
Y_train = Y_train.values
Y_validation = Y_validation.values
for dataset, side in itertools.product([X_train, X_validation], ['left', 'right']):
dataset[side] = pad_sequences(dataset[side], maxlen=max_seq_length)
assert X_train['left'].shape == X_train['right'].shape
assert len(X_train['left']) == len(Y_train)`
TypeError Traceback (most recent call last)
in
----> 1 max_seq_length = max(train_df.question1.map(lambda x: len(x)).max(),
2 train_df.question2.map(lambda x: len(x)).max(),
3 test_df.question1.map(lambda x: len(x)).max(),
4 test_df.question2.map(lambda x: len(x)).max())
5
~.conda\envs\gpuversion\lib\site-packages\pandas\core\series.py in map(self, arg, na_action)
3628 dtype: object
3629 """
-> 3630 new_values = super()._map_values(arg, na_action=na_action)
3631 return self._constructor(new_values, index=self.index).finalize(self)
3632
~.conda\envs\gpuversion\lib\site-packages\pandas\core\base.py in _map_values(self, mapper, na_action)
1143
1144 # mapper is a function
-> 1145 new_values = map_f(values, mapper)
1146
1147 return new_values
pandas_libs\lib.pyx in pandas._libs.lib.map_infer()
in (x)
----> 1 max_seq_length = max(train_df.question1.map(lambda x: len(x)).max(),
2 train_df.question2.map(lambda x: len(x)).max(),
3 test_df.question1.map(lambda x: len(x)).max(),
4 test_df.question2.map(lambda x: len(x)).max())
5
TypeError: object of type 'float' has no len()
`
but when I use len(str(x)) to solve this issue I get another error of ValueError: sequences
must be a list of iterables. Found non-iterable: nan
Is the variable X_test never consumed in whole program ? What is this variable's purpose ?
I couldn't import Merge using the line "from keras.layers import LSTM, Embedding, Input, Merge".
So I tried changing the code to "from keras.layers import LSTM, Embedding, Input, merge" which helped in executing this line but when I was executing the below line of code I got the below error. Please help
TypeError Traceback (most recent call last)
in ()
12 # Calculates the distance as defined by the MaLSTM model
13 malstm_distance = merge(mode=lambda x: exponent_neg_manhattan_distance(x[0], x[1]),
---> 14 output_shape=lambda x: (x[0][0], 1))([left_output, right_output])
15
16 # Combine all of the above in a Model
TypeError: 'module' object is not callable
hi ,
while executing your code of node2vec following error was occurred, how to resolve it kindly suggest me
Traceback (most recent call last):
File "", line 15, in
node2vec = Node2Vec(graph, dimensions=20, walk_length=16, num_walks=100, workers=2)
File "C:\Users\pshrikant\AppData\Local\Continuum\anaconda3\lib\site-packages\node2vec\node2vec.py", line 71, in init
self.walks = self._generate_walks()
File "C:\Users\pshrikant\AppData\Local\Continuum\anaconda3\lib\site-packages\node2vec\node2vec.py", line 158, in _generate_walks
in enumerate(num_walks_lists, 1))
File "C:\Users\pshrikant\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py", line 934, in call
self.retrieve()
File "C:\Users\pshrikant\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py", line 833, in retrieve
self._output.extend(job.get(timeout=self.timeout))
TypeError: 'NoneType' object is not iterable
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.