This file contains hidden or 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
| embedding_size = 50 | |
| word_embedding_column = tf.feature_column.embedding_column( | |
| column, dimension=embedding_size) | |
| classifier = tf.estimator.DNNClassifier( | |
| hidden_units=[100], | |
| feature_columns=[word_embedding_column], | |
| model_dir=os.path.join(model_dir, 'bow_embeddings')) | |
| train_and_evaluate(classifier) |
This file contains hidden or 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
| # Load the tensor with the model weights | |
| weights = classifier.get_variable_value('linear/linear_model/x/weights').flatten() | |
| # Find biggest weights in absolute value | |
| extremes = np.concatenate((sorted_indexes[-8:], sorted_indexes[:8])) | |
| # word_inverted_index is a dictionary that maps from indexes back to tokens | |
| extreme_weights = sorted( | |
| [(weights[i], word_inverted_index[i]) for i in extremes]) | |
| # Create plot | |
| y_pos = np.arange(len(extreme_weights)) | |
| plt.bar(y_pos, [pair[0] for pair in extreme_weights], align='center', alpha=0.5) |
This file contains hidden or 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 train_and_evaluate(classifier): | |
| classifier.train(input_fn=train_input_fn, steps=25000) | |
| eval_results = classifier.evaluate(input_fn=eval_input_fn) | |
| predictions = np.array([p['logistic'][0] for p in classifier.predict(input_fn=eval_input_fn)]) | |
| tf.reset_default_graph() | |
| # Add a PR summary in addition to the summaries that the classifier writes | |
| pr = summary_lib.pr_curve('precision_recall', predictions=predictions, labels=y_test.astype(bool), num_thresholds=21) | |
| with tf.Session() as sess: | |
| writer = tf.summary.FileWriter(os.path.join(classifier.model_dir, 'eval'), sess.graph) | |
| writer.add_summary(sess.run(pr), global_step=0) |
This file contains hidden or 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
| column = tf.feature_column.categorical_column_with_identity('x', vocab_size) | |
| classifier = tf.estimator.LinearClassifier( | |
| feature_columns=[column], | |
| model_dir=os.path.join(model_dir, 'bow_sparse')) |
This file contains hidden or 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
| x_len_train = np.array([min(len(x), sentence_size) for x in x_train_variable]) | |
| x_len_test = np.array([min(len(x), sentence_size) for x in x_test_variable]) | |
| def parser(x, length, y): | |
| features = {"x": x, "len": length} | |
| return features, y | |
| def train_input_fn(): | |
| dataset = tf.data.Dataset.from_tensor_slices((x_train, x_len_train, y_train)) | |
| dataset = dataset.shuffle(buffer_size=25000) |
This file contains hidden or 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
| vocab_size = 5000 | |
| sentence_size = 200 | |
| (x_train_variable, y_train), (x_test_variable, y_test) = imdb.load_data(num_words=vocab_size) | |
| x_train = sequence.pad_sequences( | |
| x_train_variable, | |
| maxlen=sentence_size, | |
| padding='post', | |
| value=0) | |
| x_test = sequence.pad_sequences( | |
| x_test_variable, |
This file contains hidden or 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
| { | |
| "expectedInputs": [{ | |
| "possibleIntents": [{ | |
| "inputValueData": { | |
| "listSelect": {"items": [ | |
| { | |
| "optionInfo": { | |
| "synonyms": [], | |
| "key": "La sentida carta del hijo de Débora Pérez Volpin: \"Tranquila mami, estamos bien y te extrañamos muchísimo\"" | |
| }, |
This file contains hidden or 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
| { | |
| "speech": "Sure!", | |
| "contextOut": [ | |
| { | |
| "name": "_actions_on_google_", | |
| "lifespan": 100, | |
| "parameters": {} | |
| } | |
| ], | |
| "data": { |
This file contains hidden or 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
| { | |
| "speech": "The next holiday is in 12 days.\nWhat do you want to do next?", | |
| "contextOut": [ | |
| { | |
| "name": "_actions_on_google_", | |
| "lifespan": 100, | |
| "parameters": {} | |
| } | |
| ], | |
| "data": { |
This file contains hidden or 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
| curl -X POST -H "Content-Type: application/json" -d '{ | |
| "recipient":{ | |
| "id":"USER_ID" | |
| }, | |
| "message":{ | |
| "text":"Pick a color:", | |
| "quick_replies":[ | |
| { | |
| "content_type":"text", | |
| "title":"Red", |