|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/tools/__init__.py) |

Tools and APIs for preparing data for Neural Structured Learning.

In addition to the functions exported here, two of the modules can be invoked
from the command-line.

Sample usage for running the graph builder:

`python -m neural_structured_learning.tools.build_graph` \[*flags* \]
*embedding_file.tfr... output_graph.tsv*

Sample usage for preparing input for graph-based NSL:

`python -m neural_structured_learning.tools.pack_nbrs` \[*flags* \]
*labeled.tfr unlabeled.tfr graph.tsv output.tfr*

For details about these programs' flags, run these commands:

    $ python -m neural_structured_learning.tools.build_graph --help
    $ python -m neural_structured_learning.tools.pack_nbrs --help

## Modules

[`graph_utils`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/graph_utils) module: Utility functions for manipulating (weighted) graphs.

## Functions

[`add_edge(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/add_edge): Adds an edge to a given graph.

[`add_undirected_edges(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/add_undirected_edges): Makes all edges of the given `graph` bi-directional.

[`build_graph(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/build_graph): Like [`nsl.tools.build_graph_from_config`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/build_graph_from_config), but with individual parameters.

[`build_graph_from_config(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/build_graph_from_config): Builds a graph based on dense embeddings and persists it in TSV format.

[`pack_nbrs(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/pack_nbrs): Prepares input for graph-based Neural Structured Learning and persists it.

[`read_tsv_graph(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/read_tsv_graph): Reads the file `filename` containing graph edges in TSV format.

[`write_tsv_graph(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/tools/write_tsv_graph): Writes the given `graph` to the file `filename` in TSV format.