Welcome to Colaboratory!

Colaboratory is a Google research project created to help disseminate machine learning education and research. It's a Jupyter notebook environment that requires no setup to use and runs entirely in the cloud.

Colaboratory notebooks are stored in Google Drive and can be shared just as you would with Google Docs or Sheets. Colaboratory is free to use.

For more information, see our FAQ.

Local runtime support

Colab also supports connecting to a Jupyter runtime on your local machine. For more information, see our documentation.

Python 3

Colaboratory supports both Python2 and Python3 for code execution.

  • When creating a new notebook, you'll have the choice between Python 2 and Python 3.
  • You can also change the language associated with a notebook; this information will be written into the .ipynb file itself, and thus will be preserved for future sessions.

In [0]:
import sys
print('Hello, Colaboratory from Python {}!'.format(sys.version_info[0]))


Hello, Colaboratory from Python 3!

TensorFlow execution

Colaboratory allows you to execute TensorFlow code in your browser with a single click. The example below adds two matrices.

$\begin{bmatrix}

  1. & 1. & 1. \
  2. & 1. & 1. \ \end{bmatrix} + \begin{bmatrix}
  3. & 2. & 3. \
  4. & 5. & 6. \ \end{bmatrix} = \begin{bmatrix}
  5. & 3. & 4. \
  6. & 6. & 7. \ \end{bmatrix}$

In [0]:
import tensorflow as tf
import numpy as np

with tf.Session():
  input1 = tf.constant(1.0, shape=[2, 3])
  input2 = tf.constant(np.reshape(np.arange(1.0, 7.0, dtype=np.float32), (2, 3)))
  output = tf.add(input1, input2)
  result = output.eval()

result


Out[0]:
array([[ 2.,  3.,  4.],
       [ 5.,  6.,  7.]], dtype=float32)

Visualization

Colaboratory includes widely used libraries like matplotlib, simplifying visualization.


In [0]:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = [x_i + np.random.randn(1) for x_i in x]
a, b = np.polyfit(x, y, 1)
_ = plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-')


Want to use a new library? pip install it. For recipes to import commonly used libraries, refer to the importing libraries example notebook


In [0]:
# Only needs to be run once at the top of the notebook.
!pip install -q matplotlib-venn

# Now the newly-installed library can be used anywhere else in the notebook.
from matplotlib_venn import venn2
_ = venn2(subsets = (3, 2, 1))


Forms

Forms can be used to parameterize code. See the forms example notebook for more details.


In [0]:
#@title Examples

text = 'value' #@param 
date_input = '2018-03-22' #@param {type:"date"}
number_slider = 0.5 #@param {type:"slider", min:-1, max:1, step:0.1}
dropdown = '1st option' #@param ["1st option", "2nd option", "3rd option"]