选自Medium
机器之心编译
参与:一鸣、李亚洲
今日,谷歌 TensorFlow 宣布推出神经结构学习(NSL)开源框架,它使用神经图学习方法来训练带有图和结构化数据的神经网络。
项目地址:https://github.com/tensorflow/neural-structured-learning
python pack_nbrs.py --max_nbrs=5 \
labeled_data.tfr \
unlabeled_data.tfr \
graph.tsv \
merged_examples.tfr
import neural_structured_learning as nsl
# Create a custom model — sequential, functional, or subclass.
base_model = tf.keras.Sequential(…)
# Wrap the custom model with graph regularization.
graph_config = nsl.configs.GraphRegConfig(
neighbor_config=nsl.configs.GraphNeighborConfig(max_neighbors=1))
graph_model = nsl.keras.GraphRegularization(base_model, graph_config)
# Compile, train, and evaluate.
graph_model.compile(optimizer=’adam’,
loss=tf.keras.losses.SparseCategoricalCrossentropy(), metrics=[‘accuracy’])
graph_model.fit(train_dataset, epochs=5)
graph_model.evaluate(test_dataset)
import neural_structured_learning as nsl # Create a custom model — sequential, functional, or subclass.
base_model = tf.keras.Sequential(…)# Wrap the custom model with graph regularization.
graph_config = nsl.configs.GraphRegConfig(
neighbor_config = nsl.configs.GraphNeighborConfig(max_neighbors=1))
graph_model = nsl.keras.GraphRegularization(base_model, graph_config) # Compile, train, and evaluate.
graph_model.compile(optimizer=’adam’,
loss=tf.keras.losses.SparseCategoricalCrossentropy(), metrics=[‘accuracy’])
graph_model.fit(train_dataset, epochs=5)
graph_model.evaluate(test_dataset)