我需要在输出中添加天气字符串,我该怎么做?
weather_data_train = list()
for j in range(0,len(weather_sents_train)):
weather_tokens = weather_sents_train[j].split()
weather_dict = {}
for key in weather_tokens:
weather_dict[key] = True
weather_data_train.append(weather_dict)
我得到的输出
[{'today': True, 'it': True, 'is': True, 'raining': True},
{'looking': True, 'cloudy': True, 'today': True},
{'it': True, 'is': True, 'nice': True, 'weather': True}]
我想要得到的输出
[({'today': True, 'it': True, 'is': True, 'raining': True}, 'weather'),
({'looking': True, 'cloudy': True, 'today': True}, 'weather'),
({'it': True, 'is': True, 'nice': True, 'weather': True}, 'weather')]
答案 0 :(得分:0)
您可以将dict用第二个import tensorflow as tf
# make a converter object from the saved tensorflow file
converter = tf.lite.TFLiteConverter.from_frozen_graph('/content/mnist.pb',
input_arrays=['main_input'], # input arrays
output_arrays=['add_10'] # output arrays as told in upper in my model case it si add_10
)
# tell converter which type of optimization techniques to use
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# to view the best option for optimization read documentation of tflite about optimization go to this link https://www.tensorflow.org/lite/guide/get_started#4_optimize_your_model_optional
# convert the model
tf_lite_model = converter.convert()
# save the converted model
open('eye_state_model_tensorFlowopt.tflite', 'wb').write(tf_lite_model)
括在一个元组中。
更改:
'weather'
收件人:
weather_data_train.append(weather_dict)
或者,您可以使用列表理解来重写代码:
weather_data_train.append((weather_dict, 'weather'))