Apply to speak at TensorFlow World. Deadline April 23rd. Propose talk

Contribute to the TensorFlow documentation

TensorFlow welcomes documentation contributions—if you improve the documentation, you improve the TensorFlow library itself. Documentation on tensorflow.org falls into the following categories:

  • API reference —The API reference docs are generated from docstrings in the TensorFlow source code.
  • Narrative documentation —These are tutorials, guides, and other writing that's not part of the TensorFlow code. This documentation is in the tensorflow/docs GitHub repository.
  • Community translations —These are guides and tutorials translated by the community. All community translations live in the tensorflow/docs repo.

Some TensorFlow projects keep documentation source files near the code in a separate repository, usually in a docs/ directory. See the project's CONTRIBUTING.md file or contact the maintainer to contribute.

To participate in the TensorFlow docs community:

API reference

To update reference documentation, find the source file and edit the symbol's docstring. Many API reference pages on tensorflow.org include a link to the source file where the symbol is defined. Docstrings support Markdown and can be (approximately) previewed using any Markdown previewer.

For reference documentation quality and how to get involved with doc sprints and the community, see TensorFlow 2.0 API Docs.

Versions and branches

The site's API reference version defaults to the latest stable binary—this matches the package installed with pip install tensorflow.

The default TensorFlow package is built from the stable branch rX.x in the main tensorflow/tensorflow repo. The reference documentation is generated from code comments and docstrings in the source code for Python, C++, and Java.

Previous versions of the TensorFlow documentation are available as rX.x branches in the TensorFlow Docs repository. These branches are added when a new version is released.

Build API docs

Python reference

The tensorflow_docs package includes the generator for the Python API reference docs. To install:

pip install git+https://github.com/tensorflow/docs

To generate the TensorFlow 2.0 reference docs, use the tensorflow/tools/docs/generate2.py script:

git clone https://github.com/tensorflow/tensorflow tensorflow
cd tensorflow/tensorflow/tools/docs
pip install tensorflow==2.0.0-alpha0
python generate2.py --output_dir=/tmp/out

Narrative documentation

TensorFlow guides and tutorials are written as Markdown files and interactive Jupyter notebooks. Notebooks can be run in your browser using Google Colaboratory. The narrative docs on tensorflow.org are built from the tensorflow/docs master branch. Older versions are available in GitHub on the rX.x release branches.

Simple changes

The easiest way to make straightforward documentation updates and fixes is to use GitHub's web-based file editor. Browse the tensorflow/docs repository to find the Markdown or notebook file that roughly corresponds to the tensorflow.org URL structure. In the upper right corner of the file view, click the pencil icon to open the file editor. Edit the file and then submit a new pull request.

Set up a local Git repo

For multi-file edits or more complex updates, it's better to use a local Git workflow to create a pull request.

The following Git steps are only required the first time you set up a local project.

Fork the tensorflow/docs repo

On the tensorflow/docs GitHub page, click the Fork button to create your own repo copy under your GitHub account. Once forked, you're responsible for keeping your repo copy up-to-date with the upstream TensorFlow repo.

Clone your repo

Download a copy of your remote username/docs repo to your local machine. This is the working directory where you will make changes:

git clone git@github.com:username/docs
cd ./docs

Add an upstream repo to keep up-to-date (optional)

To keep your local repository in sync with tensorflow/docs, add an upstream remote to download the latest changes.

Add a remote:

git remote add upstream git@github.com:tensorflow/docs.git

# View remote repos
git remote -v
origin    git@github.com:username/docs.git (fetch)
origin    git@github.com:username/docs.git (push)
upstream  git@github.com:tensorflow/docs.git (fetch)
upstream  git@github.com:tensorflow/docs.git (push)

To update:

git checkout master
git pull upstream master

git push  # Push changes to your GitHub account (defaults to origin)

GitHub workflow

1. Create a new branch

After you update your repo from tensorflow/docs, create a new branch from the local master branch:

git checkout -b feature-name

git branch  # List local branches
  master
* feature-name

2. Make changes

Edit files in your favorite editor and please follow the TensorFlow documentation style guide.

Commit your file change:

# View changes
git status  # See which files have changed
git diff    # See changes within files

git add path/to/file.md
git commit -m "Your meaningful commit message for the change."

Add more commits, as necessary.

3. Create a pull request

Upload your local branch to your remote GitHub repo (github.com/username/docs):

git push

After the push completes, a message may display a URL to automatically submit a pull request to the upstream repo. If not, go to the tensorflow/docs repo—or your own repo—and GitHub will prompt you to create a pull request.

4. Review

Maintainers and other contributors will review your pull request. Please participate in the discussion and make the requested changes. When your pull request is approved, it will be merged into the upstream TensorFlow docs repo.

There is a separate publishing step to update tensorflow.org from the GitHub repo. Typically, changes are batched together and the site is updated on a regular cadence.

Interactive notebooks

While it's possible to edit the notebook JSON file with GitHub's web-based file editor, it's not recommended since malformed JSON can corrupt the file. Make sure to test the notebook before submitting a pull request.

Google Colaboratory is a hosted notebook environment that makes it easy to edit—and run—notebook documentation. Notebooks in GitHub are loaded in Google Colab by passing the path to the Colab URL, for example, the notebook located in GitHub here: https://github.com/tensorflow/docs/blob/master/site/en/tutorials/keras/basic_classification.ipynb
can be loaded into Google Colab at this URL: https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/keras/basic_classification.ipynb

There is an Open in Colab Chrome extension that performs this URL substitution when browsing a notebook on GitHub. This is useful when opening a notebook in your repo fork, because the top buttons always link to the TensorFlow Docs master branch.

Edit in Colab

Within the Google Colab environment, double-click cells to edit text and code blocks. Text cells use Markdown and should follow the TensorFlow docs style guide.

Download notebook files from Colab with File > Download .pynb. Commit this file to your local Git repo and send a pull request.

To create a new notebook, copy and edit the TensorFlow notebook template.

Colab-GitHub workflow

Instead of downloading a notebook file and using a local Git workflow, you can edit and update your forked GitHub repo directly from Google Colab:

  1. In your forked username/docs repo, use the GitHub web UI to create a new branch.
  2. Navigate to the notebook file to edit.
  3. Open the notebook in Google Colab: use the URL swap or the Open in Colab Chrome extension.
  4. Edit the notebook in Colab.
  5. Commit the changes to your repo from Colab with File > Save a copy in GitHub.... The save dialog should link to the appropriate repo and branch. Add a meaningful commit message.
  6. After saving, browse to your repo or the tensorflow/docs repo, GitHub should prompt you to create a pull request.
  7. The pull request is reviewed by maintainers.

Community translations

Community translations are a great way to make TensorFlow accessible all over the world. To update a translation, find or add a file in the language directory that matches the same directory structure of the en/ directory. The English docs are the source-of-truth and translations should follow these guides as close as possible. That said, translations are written for the communities they serve. If the English terminology, phrasing, style, or tone does not translate to another language, please use a translation appropriate for the reader.

There are language-specific docs groups that make it easier for translation contributors to organize. Please join if you're an author, reviewer, or just interested in building out TensorFlow.org content for the community:

Review notifications

All documentation updates require a review. To collaborate more efficiently with the TensorFlow translation communities, here are some ways to keep on top of language-specific activity:

  • Join a language group listed above to receive an email for any created pull request that touches the site/lang directory for that language.
  • Add your GitHub username to the site/<lang>/REVIEWERS file to get automatically comment-tagged in a pull request. When comment-tagged, GitHub will send you notifications for all changes and discussion in that pull request.

Keep code up-to-date in translations

For an open source project like TensorFlow, keeping documentation up-to-date is challenging. After talking with the community, readers of translated content will tolerate text that is a little out-of-date, but out-of-date code is frustrating. To make it easier to keep the code in sync, use the nb-code-sync tool for the translated notebooks:

./tools/nb_code_sync.py [--lang=en] site/lang/notebook.ipynb

This script reads the code cells of a language notebook and check it against the English version. After stripping the comments, it compares the code blocks and updates the language notebook if they are different. This tool is particularly useful with an interactive git workflow to selectively add hunks of the file to the commit using: git add --patch site/lang/notebook.ipynb