This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
history=model.fit([x_tr,y_tr[:,:-1]], y_tr.reshape(y_tr.shape[0],y_tr.shape[1], 1)[:,1:] ,epochs=50,callbacks=[es],batch_size=512, validation_data=([x_val,y_val[:,:-1]], y_val.reshape(y_val.shape[0],y_val.shape[1], 1)[:,1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot | |
pyplot.plot(history.history['loss'], label='train') | |
pyplot.plot(history.history['val_loss'], label='test') | |
pyplot.legend() pyplot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverse_target_word_index=y_tokenizer.index_word | |
reverse_source_word_index=x_tokenizer.index_word | |
target_word_index=y_tokenizer.word_index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoder inference | |
encoder_model = Model(inputs=encoder_inputs,outputs=[encoder_outputs, state_h, state_c]) | |
# decoder inference | |
# Below tensors will hold the states of the previous time step | |
decoder_state_input_h = Input(shape=(latent_dim,)) | |
decoder_state_input_c = Input(shape=(latent_dim,)) | |
decoder_hidden_state_input = Input(shape=(max_len_text,latent_dim)) | |
# Get the embeddings of the decoder sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decode_sequence(input_seq): | |
# Encode the input as state vectors. | |
e_out, e_h, e_c = encoder_model.predict(input_seq) | |
# Generate empty target sequence of length 1. | |
target_seq = np.zeros((1,1)) | |
# Chose the 'start' word as the first word of the target sequence | |
target_seq[0, 0] = target_word_index['start'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def seq2summary(input_seq): | |
newString='' | |
for i in input_seq: | |
if((i!=0 and i!=target_word_index['start']) and i!=target_word_index['end']): | |
newString=newString+reverse_target_word_index[i]+' ' | |
return newString | |
def seq2text(input_seq): | |
newString='' | |
for i in input_seq: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(len(x_val)): | |
print("Review:",seq2text(x_val[i])) | |
print("Original summary:",seq2summary(y_val[i])) | |
print("Predicted summary:",decode_sequence(x_val[i].reshape(1,max_len_text))) | |
print("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import librosa #for audio processing | |
import IPython.display as ipd | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.io import wavfile #for audio processing | |
import warnings | |
warnings.filterwarnings("ignore") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_audio_path = '../input/tensorflow-speech-recognition-challenge/train/audio/' | |
samples, sample_rate = librosa.load(train_audio_path+'yes/0a7c2a8d_nohash_0.wav', sr = 16000) | |
fig = plt.figure(figsize=(14, 8)) | |
ax1 = fig.add_subplot(211) | |
ax1.set_title('Raw wave of ' + '../input/train/audio/yes/0a7c2a8d_nohash_0.wav') | |
ax1.set_xlabel('time') | |
ax1.set_ylabel('Amplitude') | |
ax1.plot(np.linspace(0, sample_rate/len(samples), sample_rate), samples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
labels=os.listdir(train_audio_path) | |
#find count of each label and plot bar graph | |
no_of_recordings=[] | |
for label in labels: | |
waves = [f for f in os.listdir(train_audio_path + '/'+ label) if f.endswith('.wav')] | |
no_of_recordings.append(len(waves)) | |
#plot | |
plt.figure(figsize=(30,5)) |