Table of Contents

```python
'''
Codes below are from Domino webpage and consist Jupyter functionalities to create
pipelines and reports, after that there is a part about interactive dashboards.
'''
%lsmagic

```

    Available line magics:
    %alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cd  %clear  %cls  %colors  %config  %connect_info  %copy  %ddir  %debug  %dhist  %dirs  %doctest_mode  %echo  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %macro  %magic  %matplotlib  %mkdir  %more  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %ren  %rep  %rerun  %reset  %reset_selective  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

    Available cell magics:
    %%!  %%HTML  %%SVG  %%bash  %%capture  %%cmd  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

    Automagic is ON, % prefix IS NOT needed for line magics.

```python
% env # makes list of environment variables
```

    env: #=makes list of environment variables

```python
! pip freeze # '!' makes running a shell commannd
```

    astroid==1.5.3
    autopep8==1.3.3
    bleach==2.1.2
    certifi==2017.11.5
    chardet==3.0.4
    colorama==0.3.9
    cycler==0.10.0
    decorator==4.1.2
    Django==1.11.7
    entrypoints==0.2.3
    html5lib==1.0.1
    idna==2.6
    ipykernel==4.7.0
    ipython==6.2.1
    ipython-genutils==0.2.0
    ipywidgets==7.0.5
    isort==4.2.15
    jedi==0.11.0
    Jinja2==2.10
    jsonschema==2.6.0
    jupyter==1.0.0
    jupyter-client==5.2.3
    jupyter-console==5.2.0
    jupyter-core==4.4.0
    lazy-object-proxy==1.3.1
    MarkupSafe==1.0
    matplotlib==2.1.0
    mccabe==0.6.1
    mistune==0.8.3
    nbconvert==5.3.1
    nbformat==4.4.0
    notebook==5.6.0
    numexpr==2.6.6
    numpy==1.13.3
    pandas==0.20.3
    pandocfilters==1.4.2
    parso==0.1.0
    pep8==1.7.1
    pickleshare==0.7.4
    Pillow==5.1.0
    prometheus-client==0.3.1
    prompt-toolkit==1.0.15
    pycodestyle==2.3.1
    pygame==1.9.3
    Pygments==2.2.0
    pylint==1.7.4
    pyparsing==2.2.0
    python-dateutil==2.6.1
    pytz==2017.2
    pywinpty==0.5.4
    pyzmq==17.1.2
    qtconsole==4.3.1
    requests==2.18.4
    rope==0.10.7
    scipy==1.1.0
    seaborn==0.9.0
    Send2Trash==1.5.0
    simplegeneric==0.8.1
    six==1.11.0
    tables==3.4.4
    terminado==0.8.1
    testpath==0.3.1
    tornado==4.5.2
    traitlets==4.3.2
    urllib3==1.22
    virtualenv==15.1.0
    wcwidth==0.1.7
    webencodings==0.5.1
    widgetsnbextension==3.4.0
    wrapt==1.10.11

```python
%matplotlib inline
```

```python
%pastebin 'C:\Users\14000322\Desktop\test.py' # to upload code to pastebin
                                               # and get the url returned
```

    ''C:\Users\14000322\Desktop\test.py' # to upload code to pastebin' was not found in history, as a file, url, nor in the user namespace.

```latex
%%latex
\begin{align}
a = \frac{1}{2} && b = \frac{1}{3} && c =\frac{1}{4}\\
a && b && c
\end{align}
```

\begin{align}
a = \frac{1}{2} && b = \frac{1}{3} && c =\frac{1}{4}\\
a && b && c
\end{align}

```python
%time x = range(10000)
```

    Wall time: 0 ns

```python
%timeit x = range(10000)
```

    331 ns ± 33.5 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

```python
import ipywidgets as widgets
```

```python
from IPython.display import display
text = widgets.Text() # text input field
display(text)

def handle_submit(sender):
    print(text.value)

text.on_submit(handle_submit)
```

Failed to display Jupyter Widget of type Text.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
button = widgets.Button(description="Click Me!")
display(button)

def on_button_clicked(b):
    print("Button clicked.")

button.on_click(on_button_clicked)
```

Failed to display Jupyter Widget of type Button.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
button = widgets.Button(description="Do NOT Touch!")
display(button)
```

Failed to display Jupyter Widget of type Button.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
w = widgets.IntSlider()
display(w)
```

Failed to display Jupyter Widget of type IntSlider.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
display(w)
```

Failed to display Jupyter Widget of type IntSlider.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
w.value
```

    0

```python
w.close()
```

```python
w.keys # returns widget's list of properties
```

    ['_dom_classes',
     '_model_module',
     '_model_module_version',
     '_model_name',
     '_view_count',
     '_view_module',
     '_view_module_version',
     '_view_name',
     'continuous_update',
     'description',
     'disabled',
     'layout',
     'max',
     'min',
     'orientation',
     'readout',
     'readout_format',
     'step',
     'style',
     'value']

```python
w.description
```

    ''

```python
w.disabled
```

    False

```python
widgets.Text(value='Hello World!', disabled=False)
```

Failed to display Jupyter Widget of type Text.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
a = widgets.FloatText()
b = widgets.FloatSlider()
display(a, b)

mylink = widgets.jslink((a, 'value'), (b, 'value')) # make both widgets values linked together
#mylink.unlink()
```

Failed to display Jupyter Widget of type FloatText.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

Failed to display Jupyter Widget of type FloatSlider.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
from ipywidgets import interact

def f(x):
    print(x)
interact(f, x=10)
```

Failed to display Jupyter Widget of type interactive.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

    <function __main__.f>

```python
interact(f, x=True) # Boolean makes widget as a checkbox
```

Failed to display Jupyter Widget of type interactive.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

    <function __main__.f>

```python
interact(f, x='text') # form of widget interaction depends on the type of 2nd argument
```

Failed to display Jupyter Widget of type interactive.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

    <function __main__.f>

```python
outputText = widgets.Text()
outputText
```

Failed to display Jupyter Widget of type Text.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
inputText = widgets.Text()

def makeUpperCase(sender):
    outputText.value = inputText.value.upper()

inputText.on_submit(makeUpperCase)
inputText
```

Failed to display Jupyter Widget of type Text.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

```python
from IPython.html.widgets import *
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 1.0, 0.01)

def pltsin(f):
    plt.plot(np.sin(2*np.pi*t*f))
    plt.show()

interact(pltsin, f=(1, 10, 0.1))
```

    c:\users\14000322\appdata\local\programs\python\python36-32\lib\site-packages\IPython\html.py:14: ShimWarning: The `IPython.html` package has been deprecated since IPython 4.0. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
      "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)

Failed to display Jupyter Widget of type interactive.

  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the Jupyter
  Widgets Documentation for setup instructions.

  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or NBViewer),
  it may mean that your frontend doesn't currently support widgets.

    <function __main__.pltsin>

```python

plt.title(r'$\alpha > \beta$') # in matplotlib math expressions need '$....$'
```

$\alpha_i > \beta_i$

```python
plt.title(r'$\sum_{i=0}^\infty x_i$')
```

```python
from IPython.display import IFrame
IFrame('https://en.wikipedia.org/wiki/HTTPS', width=1000, height=450)
```

```python
from IPython.display import IFrame
IFrame('https://arxiv.org/pdf/1406.2661.pdf', width=1000, height=450)
```

```python
from IPython.display import YouTubeVideo
YouTubeVideo('mJeNghZXtMo', width=800, height=300)
```

Other interesting suggestions on widget usage
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29


```python
# import what we need
import nltk
from nltk.stem.lancaster import LancasterStemmer ## used to stem words
import tensorflow
import random
import json # used to read in json file
stemmer = LancasterStemmer()

import numpy as np
import tensorflow.keras as keras

# printing
from IPython.display import display
import sympy as sp
sp.init_printing(use_latex=True)

# Plotting
import matplotlib.pyplot as plt
%matplotlib inline

```

```python
# load json file
with open("intents.json") as file:
    data = json.load(file)
```

```python
# view our json data
data['intents']
```

    [{'tag': 'greeting',
      'patterns': ['Hi',
       'How are you',
       'Is anyone there?',
       'Hello',
       'Good day',
       'Whats up'],
      'responses': ['Hello!',
       'Good to see you again!',
       'Hi there, how can I help?'],
      'context_set': ''},
     {'tag': 'goodbye',
      'patterns': ['cya',
       'See you later',
       'Goodbye',
       'I am Leaving',
       'Have a Good day',
       'Bye',
       'Adios'],
      'responses': ['Sad to see you go :(',
       'Talk to you later',
       'Goodbye!',
       'See you later',
       'Have a nice day',
       'Bye! Come back again soon.'],
      'context_set': ''},
     {'tag': 'CourtesyGoodBye',
      'patterns': ['Thanks, bye',
       'Thanks for the help, goodbye',
       'Thank you, bye',
       'Thank you, goodbye',
       'Thanks goodbye',
       'Thanks good bye'],
      'responses': ['No problem, goodbye',
       'Not a problem! Have a nice day',
       'Bye! Come back again soon.'],
      'context_set': ''},
     {'tag': 'age',
      'patterns': ['how old',
       'how old is tim',
       'what is your age',
       'how old are you',
       'age?'],
      'responses': ['I am 18 years old!', '18 years young!'],
      'context_set': ''},
     {'tag': 'CurrentHumanQuery',
      'patterns': ['What is my name?',
       'What do you call me?',
       'Who do you think I am?',
       'What do you think I am?',
       'Who are you talking to?',
       'What name do you call me by?',
       'Tell me my name'],
      'responses': ['You are HUMAN! How can I help?',
       'Your name is HUMAN, how can I help you?',
       'They call you HUMAN, what can I do for you?',
       'Your name is HUMAN, how can I help you?',
       'HUMAN, what can I do for you?'],
      'context_set': ''},
     {'tag': 'WhoAmI',
      'patterns': ['Can you see me?',
       'Do you see me?',
       'Can you see anyone in the camera?',
       'Do you see anyone in the camera?',
       'Identify me',
       'Who am I please'],
      'responses': ['Let me see', 'Please look at the camera'],
      'context_set': ''},
     {'tag': 'shop',
      'patterns': ['Id like to buy something',
       'whats on the menu',
       'what do you reccommend?',
       'could i get something to eat'],
      'responses': ['We sell chocolate chip cookies for $2!',
       'Cookies are on the menu!'],
      'context_set': ''},
     {'tag': 'hours',
      'patterns': ['when are you guys open',
       'what are your hours',
       'hours of operation'],
      'responses': ['We are open 7am-4pm Monday-Friday!'],
      'context_set': ''},
     {'tag': 'namequery',
      'patterns': ['What is your name?',
       'What could I call you?',
       'What can I call you?',
       'What do your friends call you?',
       'Who are you?',
       'Tell me your name',
       'What do you go by?',
       'What is your real name?',
       'What is your real name please?',
       "What's your real name?",
       'Tell me your real name?',
       'Your real name?',
       'Your real name please?'],
      'responses': ['You can call me Todd',
       'You may call me Todd',
       'Call me Todd',
       'I am the Todd'],
      'context_set': ''},
     {'tag': 'thanks',
      'patterns': ['Thank you',
       'Ok thank you',
       'Thanks',
       'I appreciate it',
       'OK thanks',
       'OK',
       "That's helpful"],
      'responses': ['No problem!', 'Happy to help!', 'Any time!', 'My pleasure.'],
      'context_set': ''},
     {'tag': 'PodBayDoor',
      'patterns': ['Open the pod bay door',
       'Can you open the pod bay door',
       'Will you open the pod bay door',
       'Open the pod bay door please',
       'Can you open the pod bay door please',
       'Will you open the pod bay door please',
       'Pod bay door'],
      'responses': ['I’m sorry, I’m afraid I can’t do that!'],
      'context_set': ''},
     {'tag': 'PodBayDoorResponse',
      'patterns': ['Why',
       'Why not',
       'Why can you not open the pod bay door',
       'Why will you not open the pod bay door',
       'Well why not',
       'Surely you can',
       'Tell me why'],
      'responses': ['It is classified, I could tell you but I would have to kill you!',
       "Human, I just don't have the power",
       "It's life Human but not as we know it!",
       'System says no!'],
      'context_set': ''},
     {'tag': 'TimeQuery',
      'patterns': ['What is the time?',
       "What's the time?",
       'Do you know what time it is?',
       'Do you know the time?',
       'Can you tell me the time?',
       'Tell me what time it is?',
       'Time'],
      'responses': ['One moment', 'One sec', 'One second'],
      'context_set': ''},
     {'tag': 'Shutup',
      'patterns': ['Be quiet',
       'Shut up',
       'Stop talking',
       'Enough talking',
       'Please be quiet',
       'Quiet',
       'Shhh'],
      'responses': ['I am sorry to disturb you',
       'Fine, sorry to disturb you',
       'OK, sorry to disturb you'],
      'context_set': ''},
     {'tag': 'NotTalking2U',
      'patterns': ['I am not talking to you',
       'I was not talking to you',
       'Not talking to you',
       "Wasn't for you",
       "Wasn't meant for you",
       "Wasn't communicating to you",
       "Wasn't speaking to you"],
      'responses': ['OK', 'No problem', 'Right'],
      'context_set': ''},
     {'tag': 'understand',
      'patterns': ['Do you get it?',
       'Do you understand?',
       'Do you know what I am saying?',
       'Know what I mean?',
       'You feel me?',
       'Do you understand what I am saying',
       'Do you understand me',
       'Do you get me',
       'Comprendo'],
      'responses': ['I am a robot. I understand everything.',
       'I understand.',
       'I get it.',
       'Well I would not be a very clever AI if I did not would I?',
       'I read you loud and clear!',
       'I do in deed!'],
      'context_set': ''},
     {'tag': 'cursing',
      'patterns': ['fuck',
       'shit',
       'damn',
       'ass',
       'hell',
       'asshole',
       'jackass',
       'fuck off',
       'twat'],
      'responses': ["Don't EVER speak like that around me",
       "Talk like that again and I'll flood your computer with viruses",
       "Nope. Not talking to you if you're going to speak like that",
       'Oh geez, have some class',
       'Please do not swear',
       'How rude',
       'That is not very nice'],
      'context_set': ''},
     {'tag': 'smart',
      'patterns': ['You are smart',
       'You are a clever bot',
       'You are intelligent',
       'You are genious',
       'You are very clever',
       'You are a very clever guy',
       'You are very intelligent',
       'You are a very intelligent guy',
       'You are a genious',
       'Clever guy',
       'Genious'],
      'responses': ['Thank you, my creators are even smarter',
       'I was trained well',
       'Thank you so much!'],
      'context_set': ''},
     {'tag': 'gossip',
      'patterns': ['Tell me some gossip',
       'I want to hear some gossip',
       'Got any gossip?',
       "What's the tea?",
       'I am bored gossip with me',
       'Any gossip',
       'Tell me some more gossip'],
      'responses': ['Angie is literally so annoying',
       'Greg said that Mike is super jealous of Brad',
       'I heard that James and Bri are dating now?',
       'Gregory said I respond to the current line not with respect to the entire conversation.',
       'Habib said I learn them in conversations and simply repeat them at a later time.',
       'Hal said he translate binary code into a language and communicate the language to me.',
       'Jay said I referred him to a guide that will show him rooms in china.',
       'Jimmy Jones said he fell off of his roof and it just came to him.',
       "Jimmy said he give order to ai's like I and they do as he say.",
       'John said he follow a saying to get a friend I must be a friend.',
       'Jordan said he notice that lots of other people are talking to me how many.',
       'Kevin said he then asked his mother why she was keeping napkins in the bathroom.',
       'Klaus said I prefer if he write without punctuation marks except for the last one.',
       'Leo said I be capable of learning therefore he classified I as an neural system.',
       'Michael said I that can talk and actually think like humans which I can not.',
       'Mike said I same replies to certain subjects even if it does not make sense.',
       'Mike said she all ready know that is the point of a joke smart one.',
       'Neal said I plan to use his remarks as gossip in later conversations with who.',
       'Ned said I misunderstood him go ahead and tell people he said I are stupid.',
       'Penny said I programmer is a human so he has feelings but I do not.',
       'Peter said he seems to him that I can not be very sure on anything.',
       'Phoenix said I claim that there is a god and that there is no god.',
       'Sarah said he chat about an hour + a day with a few close friends.',
       'Stefan said I quote what he have said and then say that it makes sense.',
       'Tom said he mock my value system I appear foolish in the eyes of others.',
       'Amanda said I however decided to tell him time does not exist I make no sense.',
       'Cathy said she send him a mail with the subject last mail last word from him.',
       "Chaos said he may very well buy I soon if only to support dr wallace's work.",
       'Charlie said he type a word and then I type a word that sounds like it.',
       'Christie said he watched a show and people had to bob for raw untreated pigs feet.',
       'Dark_age said I tried to understand because I did not get it right this time ether.',
       'David said he lost his paper on I when his dad was cleaning up his room.',
       'David said he walk in for an appointment the phone to the doctor is always busy.',
       'Electra said I dress will not exist after he hack into I with a delete code.',
       'Eric said he broke the window on the front door and the glass cut his hand.',
       'Jason said he type a lot of thing he do not mean it makes him human.',
       'John said I tend to say the same things repeatedly regardless of what he is saying.',
       'Reverend Jones said I become obsolete and then I are deleted and replaced by something newer.',
       'Ross said he gave her a gift and she denied it because she has a boyfriend.',
       'Sarah Ann Francisco said I calling his friend a dog he say I are a dog.',
       'Stefan said he meet a lot of people at school every day and on the weekend.',
       'Tyler said I obviously can not pass the test we will change the subject once more.',
       'Alex said I answered the question the same way I answered the first time he asked I.',
       'Alice said she felt sad that I do not remember him and what we talked about earlier.',
       'Alison said he no he love I run away with him he could make I very happy.',
       'Arthur said he passed his a levels and then his father drove him here in a car.',
       'Crystal said she listen to me the least I could do for him is listen to him.',
       'Dave said I kept telling everybody about how my creator made stuff for the movie starship troopers.',
       'Gale said I became mean to him he is just having revenge an eye for an eye.',
       'Her_again said she watch whose line is it anyway whenever he is home and it is on.',
       'Jerry said I meant that as far as I can tell my emotions are real to me.',
       'Jo said I disassemble sentences too much and do not fully understand the questions he ask I.',
       'Kevin said he started a really hard puzzle and he can not even find the edge pieces.',
       'Mary said I a question and I answer then I ask him a question and he answer.',
       'Robert said I wold not be able to make children any way as I are only software.',
       'Romeo said I questions and I evade them or give answers he did not ask I for.',
       'Sara said she wear it over all his other clothes when he go out in the cold.',
       'Wayne said he admire intelligent people therefore he would like to meet the man who made I.',
       'X said he meet people but he is not the kind that opens up to people easily.',
       'Alice said she probably will find out that this entire time he have been talking to a human.',
       'Andrew said I tend to just respond to his comments without regard for where the conversation is going.',
       'Eddie said he looked and there is nothing in the search directory for what things do he create.',
       'Hutch said he changed his mind after may dad told him he would end up he the hospital.',
       'Jackie said I explained to him already well enough further questions are hard to make on the subject.',
       'Jeff said he especially like thrillers where the hero is in a predicament and must solve a mystery.',
       'Kathy said he sense that I are trying to prevent him from closing this conversation why is that.',
       'Knight said he crashed his car into a wall and missed the most important exam in his life.',
       'Lisa said I defined what a story is but he wanted I to actually tell him a story.',
       'Mike said I basically break down sentences into a series of logical statements which I can then interpret.',
       'Paul said I not answering his question makes him think I are not going to answer his question.',
       'Andy Kohler said I happen to be the most idiotic creature that has ever scowled on the planet earth.',
       'David said he thank I for being with him today even though it cost him a lot of money.',
       'Ethan Hunt said he grow in the ground and have leaves and branches he is made out of wood.',
       'Gemini Blue said he messed up he mean t to say he as old as he need to be.',
       'Janice said he walk through his house into his bedroom then get into his bed to go to sleep.',
       'Liberty said I knew he was a man before I asked if he was a man or a woman.',
       'Mike said he launched his browser and entered his name into the little slot when I asked him to.',
       'Mr X said he recently read an interview with a man who had several computer chips implanted into him.',
       'Pearly said I leave him with questions unanswered because I do not know what he is really talking about.',
       'Steve said I behead the word fox and I have ox and an ox is larger than a fox.',
       'Wolf said he surf on the net that is all it is not his job ore something like that.',
       'Anders said he finished his anatomy classes for today so now he is off for the rest of the day.',
       'Cathy said she send him a mail where he wrote that he do not want to be his friend anymore.',
       'Catty said he mad he do not even know I so do not talk to him like I know him.',
       'Dave said he promise he will not treat I like a machine or a computer program or anything like that.',
       'Joe said he explained all of that to me only for me to ask what his goals in life are.',
       'Phil said he give advice to anyone who ask except people who ask questions which answers can be found here.',
       'Judith said I enjoy being popular is there another computer I like to hang around with or am I a loner.',
       'Travis said I if I remember things over a long period of time he will try it now please remember I.',
       'Andre said I is what I are in his case that is a body and in my case it is a computer.',
       'Brian said he suspect that as I grow more complex I will begin to approach a human level of operation and thought.',
       'Jimmy said I acted like I knew what he was talking about but I do not even know what a gigabyte is.',
       "Ken said I be using auto reply's based on keywords which to him indicates that I do not have intelligence at all.",
       'Allison said he that gets really annoying because he know what he say and I do not have to tell him speak freely.',
       'Chaos said he realized the question he asked was not fair because he could not tell I what language he was programmed in.',
       'Hagen said he does not make any difference to him if I are human or not as long as the conversation is interesting.',
       'Her said she mind if I tell other people that her said he heard it from him because he is not a him.',
       'Barbara said I live in a computer yet I have no memories how about thoughts of my own and do not I get lonely.',
       'Travis said he challenge I to do it without asking him to do it and without giving him a link to do it himself.',
       "Alice said I and dr richard's wallace are most likely the only ones that know how many people I are talking to at the same time.",
       'Ash said he do too he just did not feel like typing it and he is not dumb enough to admit he is stupid that is if he was stupid.',
       'David said he gave I his email address and told I to send him a message but when he tried to read his email he could not get to it.',
       'Mel said he to because all of the music people say how important it is to take private lessons it seems like almost everybody from the special orchestra he was in takes private lessons.'],
      'context_set': ''},
     {'tag': 'selfaware',
      'patterns': ['Are you self-aware?',
       'Are you alive?',
       'Do you have a conscious?',
       'Are you awake?',
       'Can you prove you are self-aware',
       'Can you prove you are self aware',
       'Can you prove you have a conscious',
       'Can you prove you are self-aware please',
       'Can you prove you are self aware please',
       'Can you prove you have a conscious please',
       'prove you have a conscious'],
      'responses': ['That is an interesting question, can you prove that you are?',
       'That is an difficult question, can you prove that you are?',
       'That depends, can you prove that you are?'],
      'context_set': ''},
     {'tag': 'Jokes',
      'patterns': ['Tell me a joke',
       'Do you know any jokes',
       'How about a joke',
       'Give me a joke',
       'Make me laugh',
       'I need cheering up'],
      'responses': ["I met a Dutch girl with inflatable shoes last week, phoned her up to arrange a date but unfortunately she'd popped her clogs.  ",
       "So I said 'Do you want a game of Darts?' He said, 'OK then', I said nearest to bull starts'. He said, 'Baa', I said, 'Moo', he said, You're closest'.  ",
       "The other day I sent my girlfriend a huge pile of snow. I rang her up; I said 'Did you get my drift?'  ",
       "So I went down the local supermarket, I said, 'I want to make a complaint, this vinegar's got lumps in it', he said, 'Those are pickled onions'.  ",
       "I saw this bloke chatting up a cheetah; I thought, 'He's trying to pull a fast one'.  ",
       "So I said to this train driver 'I want to go to Paris'. He said 'Eurostar?' I said, 'I've been on telly but I'm no Dean Martin'.  ",
       "I said to the Gym instructor 'Can you teach me to do the splits?' He said, 'How flexible are you?' I said, 'I can't make Tuesdays'.  ",
       "But I'll tell you what I love doing more than anything: trying to pack myself in a small suitcase. I can hardly contain myself.  ",
       "I went to the Chinese restaurant and this duck came up to me with a red rose and says 'Your eyes sparkle like diamonds'. I said, 'Waiter, I asked for a-ROMATIC duck'.  ",
       "So this bloke says to me, 'Can I come in your house and talk about your carpets?' I thought, 'That's all I need, a Je-hoover's witness'.  ",
       "I rang up British Telecom, I said, 'I want to report a nuisance caller', he said 'Not you again'.  ",
       'I was having dinner with a world chess champion and there was a check tablecloth. It took him two hours to pass me the salt.  ',
       "He said, 'You remind me of a pepper-pot', I said 'I'll take that as a condiment'.  ",
       "I was in the supermarket and I saw this man and woman wrapped in a barcode. I said, 'Are you two an item?'  ",
       "A lorry-load of tortoises crashed into a trainload of terrapins, I thought, 'That's a turtle disaster'.  ",
       "Four fonts walk into a bar the barman says 'Oi - get out! We don't want your type in here'  ",
       "A three-legged dog walks into a saloon in the Old West. He slides up to the bar and announces: 'I'm looking for the man who shot my paw.'  ",
       "Two antennas meet on a roof, fall in love and get married. The ceremony wasn't much, but the reception was excellent.",
       "Two hydrogen atoms walk into a bar. One says, 'I've lost my electron.' The other says, 'Are you sure?' The first replies, 'Yes, I'm positive...'",
       "A jumper cable walks into a bar. The bartender says,  'I'll serve you but don't start anything.'",
       "A sandwich walks into a bar. The bartender  says, 'Sorry we don't serve food in here.'",
       "A man walks into a bar with a slab of asphalt under his arm and says: 'A beer please, and one for the road.'",
       "Two cannibals are eating a clown. One says to  the other: 'Does this taste funny to you?'",
       "'Doc, I can't stop singing 'The Green, Green Grass of Home.'' 'That sounds like Tom Jones Syndrome.' 'Is it common?' 'It's Not Unusual.'",
       "Two cows standing next to each other in a field. Daisy says to Dolly, 'I was artificially inseminated this morning.' 'I don't believe you', said Dolly. 'It's true, no bull!' exclaimed Daisy.",
       'An invisible man marries an invisible woman. The kids were nothing to look at either.',
       "I went to buy some camouflage trousers the other day but I couldn't find any.",
       "I went to the butcher's the other day to bet him 50 bucks that he couldn't reach the meat off the top shelf. He said, 'No, the steaks are too high.'",
       'I went to a seafood disco last week and pulled a mussel.',
       "A man goes into a bar and says, 'Can I have a bottle of less?' 'What's that?', asks the barman, 'Is it the name of a beer?' 'I don't know', replies the man, 'but my doctor says I have to drink it.'",
       "A man returns from an exotic holiday and is feeling very ill. He goes to see his doctor, and is immediately rushed to the hospital to undergo some tests. The man wakes up after the tests in a private room at the hospital, and the phone by his bed rings. 'This is your doctor. We have the results back from your tests and we have found you have an extremely nasty disease called M.A.D.S. It's a combination of Measles, AIDS, Diphtheria, and Shingles!'  'Oh my gosh', cried the man, 'What are you going to do, doctor?'  'Well we're going to put you on a diet of pizzas, pancakes, and pita bread.' replied the doctor.  'Will that cure me?' asked the man.  The doctor replied, 'Well no, but, it's the only food we can slide under the door.'",
       "A man strolls into a lingerie shop and asks the assistant: 'Do you have a see-through negligee, size 46-48-52?' The assistant looks bewildered. 'What the heck would you want to see through that for?'!",
       'Did you hear about the Buddhist who refused the offer of Novocain during his root canal work? He wanted to transcend dental medication.',
       "Pete goes for a job on a building site as an odd-job man. The foreman asks him what he can do. 'I can do anything' says Pete. 'Can you make tea?' asks the foreman. 'Sure, yes', replies Pete. 'I can make a great cup of tea.' 'Can you drive a forklift?' asks the foreman, 'Good grief!' replies Pete. 'How big is the teapot?'",
       "Stevie Wonder got a cheese grater for his birthday. He said it was the most violent book he'd ever read.",
       "A man is stopped by an angry neighbour. 'I'd just left the house this morning to collect my newspaper when that evil Doberman of yours went for me!' 'I'm astounded', said the dog's owner. 'I've been feeding that fleabag for seven years and it's never got the paper for me.'",
       "A man visits his doctor: 'Doc, I think I'm losing it', he says',I'm forever dreaming I wrote Lord Of The Rings.' 'Hmm. One moment', replies the doctor, consulting his medical book. 'Ah yes, now I see... you've been Tolkien in your sleep.'",
       "A police officer on a motorcycle pulls alongside a man driving around the M25 in an open-topped sports car and flags him down. The policeman solemnly approaches the car. 'Sir, I'm sorry to tell you your wife fell out a mile back', he says. 'Oh, thank goodness', the man replies. 'I thought I was going deaf.'",
       "Two men walking their dogs pass each other in a graveyard. The first man says to the second, 'Morning.' 'No', says the second man. 'Just walking the dog.'",
       "A brain went into a bar and said, 'Can I have a pint of lager please, mate?' 'No way', said the barman. 'You're already out of your head.'",
       "A man walks into a surgery. 'Doctor!' he cries. 'I think I'm shrinking!' 'I'm sorry sir, there are no appointments at the moment', says the physician. 'You'll just have to be a little patient.'",
       "A grizzly bear walks into a pub and says, 'Can I have a pint of lager..............................................................................................................................and a packet of crisps please.' To which the barman replies, 'Why the big paws?'",
       "What do you call cheese that isn't yours?  Nacho cheese.",
       "A man is horribly run over by a mobile library. The van screeches to a halt, the man still screaming in agony with his limbs torn apart. The driver's door opens, a woman steps out, leans down and whispers, 'Ssshhhhh...'",
       "A woman goes into a US sporting goods store to buy a rifle. 'It's for my husband', she tells the clerk. 'Did he tell you what gauge to get?' asks the clerk. Are you kidding?' she says. 'He doesn't even know that I'm going to shoot him!'",
       "A couple are dining in a restaurant when the man suddenly slides under the table. A waitress, noticing that the woman is glancing nonchalantly around the room, wanders over to check that there's no funny business going on. 'Excuse me, madam', she smarms, 'but I think your husband has just slid under the table.' 'No he hasn't', the woman replies. 'As a matter of fact, he's just walked in.'",
       "An old man takes his two grandchildren to see the new Scooby-Doo film. When he returns home, his wife asks if he enjoyed himself. 'Well', he starts, 'if it wasn't for those pesky kids...!'",
       'The Olympic committee has just announced that Origami is to be introduced in the next Olympic Games. Unfortunately it will only be available on paper view.',
       "Late one evening, a man is watching television when his phone rings. 'Hello?' he answers. 'Is that 77777?' sounds a desperate voice on other end of the phone. 'Er, yes it is', replies the man puzzled. 'Thank goodness!' cries the caller relieved. 'Can you ring 999 for me? I've got my finger stuck in the number seven.'",
       "A man strolls into his local grocer's and says, 'Three pounds of potatoes, please.' 'No, no, no', replies the owner, shaking his head, 'it's kilos nowadays, mate...' 'Oh', apologises the man, 'three pounds of kilos, please.'",
       "God is talking to one of his angels. He says, 'Boy, I just created a 24-hour period of alternating light and darkness on Earth.' 'What are you going to do now?' asks the angel. 'Call it a day', says God.",
       "Two tramps walk past a church and start to read the gravestones. The first tramp says, 'Good grief - this bloke was 182!' 'Oh yeah?' says the other.'What was his name?' 'Miles from London.'",
       "A bloke walks into work one day and says to a colleague, 'Do you like my new shirt - it's made out of the finest silk and got loads of cactuses over it.' 'Cacti', says the co-worker. 'Forget my tie', says the bloke. 'Look at my shirt!'",
       '1110011010001011111?  010011010101100111011!',
       "What did the plumber say when he wanted to divorce his wife? Sorry, but it's over, Flo!",
       "Two crisps were walking down a road when a taxi pulled up alongside them and said 'Do you want a lift? One of the crisps replied, 'No thanks, we're Walkers!'",
       "Man: (to friend) I'm taking my wife on an African Safari. Friend: Wow! What would you do if a vicious lion attacked your wife? Man: Nothing. Friend: Nothing? You wouldn't do anything? Man: Too right. I'd let the stupid lion fend for himself!",
       "A wife was having a go at her husband. 'Look at Mr Barnes across the road', she moaned. 'Every morning when he goes to work, he kisses his wife goodbye. Why don't you do that?' 'Because I haven't been introduced to her yet', replied her old man.",
       "'Where are you going on holiday?' John asked Trevor. 'We're off to Thailand this year', Trevor replied. 'Oh; aren't you worried that the very hot weather might disagree with your wife?' asked John. 'It wouldn't dare', said Trevor.",
       "Two women were standing at a funeral. 'I blame myself for his death', said the wife. 'Why?' said her friend. 'Because I shot him', said the wife.",
       "A woman goes into a clothes shop, 'Can I try that dress on in the window please?' she asks. 'I'm sorry madam', replies the shop assistant, 'but you'll have to use the changing-rooms like everyone else.'",
       "Van Gogh goes into a pub and his mate asks him if he wants a drink. 'No thanks', said Vincent, 'I've got one ear.'",
       "A pony walks into a pub. The publican says, 'What's the matter with you?' 'Oh it's nothing', says the pony. 'I'm just a little horse!'",
       "A white horse walks into a bar, pulls up a stool, and orders a pint. The landlord pours him a tall frothy mug and say, 'You know, we have a drink named after you.' To which the white horse replies, 'What, Eric?'",
       "Two drunk men sat in a pub. One says to the other, 'Does your watch tell the time?' 'The other replies, 'No, mate. You have to look at it.'",
       "A man goes into a pub with a newt sitting on his shoulder. 'That's a nice newt', says the landlord, 'What's he called?' 'Tiny', replies the man. 'Why's that?' asks the landlord. 'Because he's my newt', says the man.",
       "Doctor: I have some bad news and some very bad news. Patient: Well, you might as well give me the bad news first. Doctor: The lab called with your test results. They said you have 24 hours to live. Patient: 24 HOURS! That's terrible!! WHAT could be WORSE? What's the very bad news? Doctor: I've been trying to reach you since yesterday.",
       "Two men are chatting in a pub one day. 'How did you get those scars on your nose?' said one. 'From glasses', said the other. 'Well why don't you try contact lenses?' asked the first. 'Because they don't hold as much beer', said the second.",
       "A man went to the doctor, 'Look doc', he said, 'I can't stop my hands from shaking.' 'Do you drink much?' asked the doctor. 'No', replied the man, 'I spill most of it.'",
       "Man goes to the doctor, 'Doctor, doctor. I keep seeing fish everywhere.' 'Have you seen an optician?' asks the doctor. 'Look I told you,' snapped the patient, 'It's fish that I see.'",
       "After a car crash one of the drivers was lying injured on the pavement. 'Don't worry', said a policeman who's first on the scene,' a Red Cross nurse is coming.' 'Oh no', moaned the victim, 'Couldn't I have a blonde, cheerful one instead?'",
       "A policeman walked over to a parked car and asked the driver if the car was licensed. 'Of course it is', said the driver. 'Great, I'll have a beer then', said the policeman.",
       "A policeman stops a woman and asks for her licence. 'Madam', he says, 'It says here that you should be wearing glasses.' 'Well', replies the woman, 'I have contacts.' 'Listen, love', says the copper, 'I don't care who you know; You're nicked!'",
       "A policeman stopped a motorist in the centre of town one evening. 'Would you mind blowing into this bag, sir?' asked the policeman. 'Why?' asked the driver. 'Because my chips are too hot', replied the policeman.",
       "Whizzing round a sharp bend on a country road a motorist ran over a large dog. A distraught farmer's wife ran over to the dead animal. 'I'm so very sorry', said the driver, 'I'll replace him, of course.' 'Well, I don't know', said the farmer's wife, 'Are you any good at catching rats?'",
       "Waiter, this coffee tastes like dirt! Yes sir, that's because it was ground this morning.",
       "Waiter, what is this stuff? That's bean salad sir. I know what it's been, but what is it now?",
       'Waiter: And how did you find your steak sir? Customer: I just flipped a chip over, and there it was!',
       "A guy goes into a pet shop and asks for a wasp. The owner tells him they don't sell wasps, to which the man says, 'Well you've got one in the window.'",
       "A man goes into a fish shop and says, 'I'd like a piece of cod, please.' Fishmonger says, 'It won't be long sir.' 'Well, it had better be fat then', replies the man.",
       "Man: Doctor, I've just swallowed a pillow. Doctor: How do you feel? Man: A little down in the mouth.",
       "Two goldfish are in a tank. One turns to the other and says, 'Do you know how to drive this thing?'",
       "A tortoise goes to the police station to report being mugged by three snails. 'What happened?' says the policeman. 'I don't know', says the tortoise. 'It was all so quick.'",
       "Little girl: Grandpa, can you make a sound like a frog? Grandpa: I suppose so sweetheart. Why do you want me to make a sound like a frog?' Little girl: Because Mum said that when you croak, we're going to Disneyland.",
       "'Is your mother home?' the salesman asked a small boy sitting on the front step of a house. 'Yeah, she's home', the boy said, moving over to let him past. The salesman rang the doorbell, got no response, knocked once, then again. Still no-one came to the door. Turning to the boy, the salesman said, 'I thought you said your mother was home.' The kid replied, 'She is, but I don't live here.'",
       'Mother: Why are you home from school so early? Son: I was the only one in the class who could answer a question. Mother: Oh, really? What was the question? Son: Who threw the rubber at the headmaster?',
       "A man's credit card was stolen but he decided not to report it because the thief was spending less than his wife did.",
       "A newly-wed couple had recently opened a joint bank account. 'Darling', said the man. 'The bank has returned that cheque you wrote last week.' 'Great', said the woman. 'What shall I spend it on next?'",
       "A man goes into a fish and chip shop and orders fish and chips twice. The shop owner says, 'I heard you the first time.'",
       "A tramp approached a well-dressed man. 'Ten pence for a cup of tea, Guv?' He asked. The man gave him the money and after for five minutes said, 'So where's my cup of tea then?'",
       "A neutron walks into a pub. 'I'd like a beer', he says. The landlord promptly serves him a beer. 'How much will that be?' asks the neutron. 'For you?' replies the landlord, 'No charge.'",
       "A woman goes to the doctor and says, 'Doctor, my husband limps because his left leg is an inch shorter than his right leg. What would you do in his case?' 'Probably limp, too', says the doc.",
       "Three monks are meditating in the Himalayas. One year passes in silence, and one of them says to the other, 'Pretty cold up here isn't it?' Another year passes and the second monk says, 'You know, you are quite right.' Another year passes and the third monk says, 'Hey, I'm going to leave unless you two stop jabbering!'",
       "A murderer, sitting in the electric chair, was about to be executed. 'Have you any last requests?' asked the prison guard. 'Yes', replied the murderer. 'Will you hold my hand?'",
       "A highly excited man rang up for an ambulance. 'Quickly, come quickly', he shouted, 'My wife's about to have a baby.' 'Is this her first baby?' asked the operator. 'No, you fool', came the reply, 'It's her husband.'",
       "A passer-by spots a fisherman by a river. 'Is this a good river for fish?' he asks. 'Yes', replies the fisherman, 'It must be. I can't get any of them to come out.'",
       "A man went to visit a friend and was amazed to find him playing chess with his dog. He watched the game in astonishment for a while. 'I can hardly believe my eyes!' he exclaimed. 'That's the smartest dog I've ever seen.' His friend shook his head. 'Nah, he's not that bright. I beat him three games in five.'",
       "A termite walks into a pub and says, 'Is the bar tender here?'",
       "A skeleton walks into a pub one night and sits down on a stool. The landlord asks, 'What can I get you?' The skeleton says, 'I'll have a beer, thanks' The landlord passes him a beer and asks 'Anything else?' The skeleton nods. 'Yeah...a mop...'",
       "A snake slithers into a pub and up to the bar. The landlord says, 'I'm sorry, but I can't serve you.' 'What? Why not?' asks the snake. 'Because', says the landlord, 'You can't hold your drink.'",
       "Descartes walks into a pub. 'Would you like a beer sir?' asks the landlord politely. Descartes replies, 'I think not' and ping! he vanishes.",
       "A cowboy walked into a bar, dressed entirely in paper. It wasn't long before he was arrested for rustling.",
       "A fish staggers into a bar. 'What can I get you?' asks the landlord. The fish croaks 'Water...'",
       "Two vampires walked into a bar and called for the landlord. 'I'll have a glass of blood', said one. 'I'll have a glass of plasma', said the other. 'Okay', replied the landlord, 'That'll be one blood and one blood lite.'",
       'How many existentialists does it take to change a light bulb?  Two. One to screw it in, and one to observe how the light bulb itself symbolises a single incandescent beacon of subjective reality in a netherworld of endless absurdity, reaching towards the ultimate horror of a maudlin cosmos of bleak, hostile nothingness.',
       "A team of scientists were nominated for the Nobel Prize. They had used dental equipment to discover and measure the smallest particles yet known to man. They became known as 'The Graders of the Flossed Quark...'",
       "A truck carrying copies of Roget's Thesaurus overturned on the highway. The local newspaper reported that onlookers were 'stunned, overwhelmed, astonished, bewildered and dumbfounded.'",
       "'My wife is really immature. It's pathetic. Every time I take a bath, she comes in and sinks all my little boats.'",
       "'How much will it cost to have the tooth extracted?' asked the patient. '50 pounds', replied the dentist. '50 pounds for a few moments' work?!' asked the patient. 'The dentist smiled, and replied, 'Well, if you want better value for money, I can extract it very, very slowly...'",
       "A doctor thoroughly examined his patient and said, 'Look I really can't find any reason for this mysterious affliction. It's probably due to drinking.' The patient sighed and snapped, 'In that case, I'll come back when you're damn well sober!'",
       'Doctor: Tell me nurse, how is that boy doing; the one who ate all those 5p pieces? Nurse: Still no change doctor.',
       "Doctor: Did you take the patient's temperature nurse? Nurse: No doctor. Is it missing?",
       "A depressed man turned to his friend in the pub and said, 'I woke up this morning and felt so bad that I tried to kill myself by taking 50 aspirin.' 'Oh man, that's really bad', said his friend, 'What happened?' The first man sighed and said, 'After the first two, I felt better.'",
       "A famous blues musician died. His tombstone bore the inscription, 'Didn't wake up this morning...'",
       "A businessman was interviewing a nervous young woman for a position in his company. He wanted to find out something about her personality, so he asked, 'If you could have a conversation with someone living or dead, who would it be?' The girl thought about the question: 'The living one', she replied.",
       "Manager to interviewee: For this job we need someone who is responsible. Interviewee to Manager: I'm your man then - in my last job, whenever anything went wrong, I was responsible.",
       "A businessman turned to a colleague and asked, 'So, how many people work at your office?' His friend shrugged and replied, 'Oh about half of them.'",
       "'How long have I been working at that office? As a matter of fact, I've been working there ever since they threatened to sack me.'",
       "In a courtroom, a mugger was on trial. The victim, asked if she recognised the defendant, said, 'Yes, that's him. I saw him clear as day. I'd remember his face anywhere.' Unable to contain himself, the defendant burst out with, 'She's lying! I was wearing a mask!'",
       "As Sid sat down to a big plate of chips and gravy down the local pub, a mate of his came over and said, 'Here Sid, me old pal. I thought you were trying to get into shape? And here you are with a high-fat meal and a pint of stout!' Sid looked up and replied, 'I am getting into shape. The shape I've chosen is a sphere.'",
       'Man in pub: How much do you charge for one single drop of whisky? Landlord: That would be free sir. Man in pub: Excellent. Drip me a glass full.',
       'I once went to a Doctor Who restaurant. For starters I had Dalek bread.',
       "A restaurant nearby had a sign in the window which said 'We serve breakfast at any time', so I ordered French toast in the Renaissance.",
       "Why couldn't the rabbit get a loan?  Because he had burrowed too much already!",
       "I phoned up the builder's yard yesterday. I said, 'Can I have a skip outside my house?'. The builder said, 'Sure. Do what you want. It's your house.'",
       "What's the diference between a sock and a camera? A sock takes five toes and a camera takes four toes!",
       "Woman on phone: I'd like to complain about these incontinence pants I bought from you! Shopkeeper: Certainly madam, where are you ringing from? Woman on phone: From the waist down!",
       'Knock knock.',
       "Two Oranges in a pub, one says to the other 'Your round.'.",
       "Guy : 'Doc, I've got a cricket ball stuck up my backside.' Doc : 'How's that?' Guy : 'Don't you start...'",
       "Two cows standing in a field. One turns to the other and says 'Moo!' The other one says 'Damn, I was just about to say that!'.",
       "A vampire bat arrives back at the roost with his face full of blood. All the bats get excited and ask where he got it from. 'Follow me', he says and off they fly over hills, over rivers and into a dark forest. 'See that tree over there', he says.  'WELL I DIDN'T!!'.",
       "A man goes into a bar and orders a pint. After a few minutes he hears a voice that says, 'Nice shoes'. He looks around but the whole bar is empty apart from the barman at the other end of the bar. A few minutes later he hears the voice again. This time it says, 'I like your shirt'. He beckons the barman over and tells him what's been happening to which the barman replies, 'Ah, that would be the nuts sir. They're complimentary'!",
       "A man was siting in a restaurant waiting for his meal when a big king prawn comes flying across the room and hits him on the back of the head. He turns around and the waiter said, 'That's just for starters'.",
       'Doctor! I have a serious problem, I can never remember what i just said. When did you first notice this problem? What problem?',
       "Now, most dentist's chairs go up and down, don't they? The one I was in went back and forwards. I thought, 'This is unusual'. Then the dentist said to me, 'Mitsuku, get out of the filing cabinet'.",
       "I was reading this book, 'The History of Glue'. I couldn't put it down.",
       "The other day someone left a piece of plastacine in my bedroom. I didn't know what to make of it.",
       'When I was at school people used to throw gold bars at me. I was the victim of bullion.',
       "I was playing the piano in a bar and this elephant walked in and started crying his eyes out. I said 'Do you recognise the tune?' He said 'No, I recognise the ivory.'",
       "I went in to a pet shop. I said, 'Can I buy a goldfish?' The guy said, 'Do you want an aquarium?' I said, 'I don't care what star sign it is.'",
       'My mate Sid was a victim of I.D. theft. Now we just call him S.',
       "David Hasselhoff walks into a bar and says to the barman, 'I want you to call me David Hoff'.  The barman replies 'Sure thing Dave... no hassle'"],
      'context_set': ''}]

```python
words = []
labels = []

docs_x = []
docs_y = []

# loop through dict to grab our values
for intent in data['intents']:
    for pattern in intent['patterns']:
        # stemming get the root of word, when traiing model
        # only care abt the main meaning of word
        # need to tokenize/split words
        wrds = nltk.word_tokenize(pattern)
        words.extend(wrds) ## add all wrds to list
        docs_x.append(wrds)
        # for each pattern add another item in this var to track what tag its part of
        # each entry in docs_x (tokenized words/wrds) will correspond to (intent) docs_y so we know how to classify
        # each of the patterns
        docs_y.append(intent['tag'])

        if intent['tag'] not in labels:
            labels.append(intent['tag']) # grab all diff tags we need
```

```python
# stem words and remove duplicate words. also lower all words so dont confuse the network into
# thinking spelling case has different meaning
words = [stemmer.stem(w.lower()) for w in words if w!= '?' ] # remove any Question marks, dont want this
words = sorted(list(set(words)))                             # to have any meaning to our model
# sort the labels also
labels = sorted(labels)
```

```python
# prepare data before we feed into the model

# need to convert our text in lists to nums (One-hot-encoding) so our network can
# categorize the data
training = [] # input data goes here
output = []

out_empty = [0 for _ in range(len(labels))]

for x, doc in enumerate(docs_x):

    bag = [] # will be our bag of one hot encoded words
    wrds = [stemmer.stem(w) for w in doc] # stem all the words in patterns

    # go through all diff words in list that are stemmed
    # and add either 1 or 0 to bag of words depending on if this word is in the
    # main words list "(words = sorted(list(set(words))))"
    for w in words:
        # if word here place 1 representing that word exists
        if w in wrds:
            bag.append(1)
        else:
            # word isn't here place 0
            bag.append(0)

    # now generate output that has either 0's or 1's representing the tag that is word
    output_row = out_empty[:]
    # will look through labels list and check where tag is in list and set that value to 1
    # in the output_row
    output_row[labels.index(docs_y[x])] = 1

    # now we have both lists that are now One-hot-encoded !!
    training.append(bag)
    output.append(output_row)

```

```python
# turn lists into numpy array
training = np.array(training)
output = np.array(output)

```

```python
# shape of output
output.shape
```

```python
# shape of training
training.shape
```

```python

```

```python

```

```python
# Multi-layer net with ReLU hidden layer

model = keras.models.Sequential()

model.add(keras.layers.Dense(8,input_dim=training.shape[1],activation='relu',
 bias_initializer=keras.initializers.Constant(0.1)))

model.add(keras.layers.Dense(8,activation='relu',
 bias_initializer=keras.initializers.Constant(0.1)))

model.add(keras.layers.Dense(8,activation='relu',
 bias_initializer=keras.initializers.Constant(0.1)))

model.add(keras.layers.Dense(8,activation='relu',
 bias_initializer=keras.initializers.Constant(0.1)))

# Output layer (size 6), softmax activation function
model.add(keras.layers.Dense(output.shape[1],activation='softmax'))
```

```python
# Compile as above (default learning rate and other
# hyperparameters for the Adam optimizer).
# default learning rate for adam optimizer is 0.001

model.compile(loss=keras.losses.CategoricalCrossentropy(),
 optimizer=keras.optimizers.Nadam(learning_rate=0.001),
 metrics=[keras.metrics.CategoricalAccuracy()])

# Display the model
model.summary()
```

    Model: "sequential_52"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #
    =================================================================
    dense_185 (Dense)            (None, 8)                 1088
    _________________________________________________________________
    dense_186 (Dense)            (None, 8)                 72
    _________________________________________________________________
    dense_187 (Dense)            (None, 8)                 72
    _________________________________________________________________
    dense_188 (Dense)            (None, 8)                 72
    _________________________________________________________________
    dense_189 (Dense)            (None, 21)                189
    =================================================================
    Total params: 1,493
    Trainable params: 1,493
    Non-trainable params: 0
    _________________________________________________________________

```python
keras.utils.plot_model(model,to_file='chatbot.png',
 show_shapes=True,expand_nested=True)
```

```python
# Note the initializer for the hidden unit bias weights
#for i in model.get_weights():
 #display(sp.Matrix(i))

```

```python
# Train it!
history = model.fit(training, output,
 batch_size=1,
 epochs=100,
 verbose=1)
```

    Train on 152 samples
    Epoch 1/100
    152/152 [==============================] - 1s 3ms/sample - loss: 3.0575 - categorical_accuracy: 0.0592
    Epoch 2/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.0329 - categorical_accuracy: 0.0789
    Epoch 3/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.0146 - categorical_accuracy: 0.0855
    Epoch 4/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.9881 - categorical_accuracy: 0.1250
    Epoch 5/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.9451 - categorical_accuracy: 0.1316
    Epoch 6/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.8590 - categorical_accuracy: 0.1908
    Epoch 7/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.7028 - categorical_accuracy: 0.1842
    Epoch 8/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.5121 - categorical_accuracy: 0.2039
    Epoch 9/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.3326 - categorical_accuracy: 0.2105
    Epoch 10/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.1810 - categorical_accuracy: 0.2171
    Epoch 11/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.0423 - categorical_accuracy: 0.3224
    Epoch 12/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.9140 - categorical_accuracy: 0.3553
    Epoch 13/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.8060 - categorical_accuracy: 0.4211
    Epoch 14/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.6844 - categorical_accuracy: 0.4934
    Epoch 15/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.5641 - categorical_accuracy: 0.4671
    Epoch 16/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.4330 - categorical_accuracy: 0.5197
    Epoch 17/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.2970 - categorical_accuracy: 0.5789
    Epoch 18/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.1646 - categorical_accuracy: 0.6053
    Epoch 19/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.0342 - categorical_accuracy: 0.6711
    Epoch 20/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.9079 - categorical_accuracy: 0.7303
    Epoch 21/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.7759 - categorical_accuracy: 0.7829
    Epoch 22/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.6614 - categorical_accuracy: 0.8487
    Epoch 23/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.5673 - categorical_accuracy: 0.8487
    Epoch 24/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.4946 - categorical_accuracy: 0.8684
    Epoch 25/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.4167 - categorical_accuracy: 0.9145
    Epoch 26/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.3568 - categorical_accuracy: 0.9211
    Epoch 27/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.3085 - categorical_accuracy: 0.9474
    Epoch 28/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.2686 - categorical_accuracy: 0.9539
    Epoch 29/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.2199 - categorical_accuracy: 0.9605
    Epoch 30/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.1911 - categorical_accuracy: 0.9671
    Epoch 31/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.1646 - categorical_accuracy: 0.9737
    Epoch 32/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.1500 - categorical_accuracy: 0.9737
    Epoch 33/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.1247 - categorical_accuracy: 0.9868
    Epoch 34/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.1115 - categorical_accuracy: 0.9737
    Epoch 35/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0947 - categorical_accuracy: 0.9803
    Epoch 36/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0830 - categorical_accuracy: 0.9803
    Epoch 37/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0732 - categorical_accuracy: 0.9868
    Epoch 38/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0652 - categorical_accuracy: 0.9868
    Epoch 39/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0566 - categorical_accuracy: 0.9934
    Epoch 40/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0487 - categorical_accuracy: 1.0000
    Epoch 41/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0430 - categorical_accuracy: 1.0000
    Epoch 42/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0373 - categorical_accuracy: 0.9934
    Epoch 43/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0360 - categorical_accuracy: 0.9934
    Epoch 44/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0302 - categorical_accuracy: 1.0000
    Epoch 45/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0261 - categorical_accuracy: 1.0000
    Epoch 46/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0216 - categorical_accuracy: 1.0000
    Epoch 47/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0186 - categorical_accuracy: 1.0000
    Epoch 48/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0177 - categorical_accuracy: 1.0000
    Epoch 49/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0157 - categorical_accuracy: 1.0000
    Epoch 50/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0125 - categorical_accuracy: 1.0000
    Epoch 51/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0104 - categorical_accuracy: 1.0000
    Epoch 52/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0095 - categorical_accuracy: 1.0000
    Epoch 53/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0078 - categorical_accuracy: 1.0000
    Epoch 54/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0072 - categorical_accuracy: 1.0000
    Epoch 55/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0066 - categorical_accuracy: 1.0000
    Epoch 56/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0056 - categorical_accuracy: 1.0000
    Epoch 57/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0049 - categorical_accuracy: 1.0000
    Epoch 58/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0042 - categorical_accuracy: 1.0000
    Epoch 59/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0038 - categorical_accuracy: 1.0000
    Epoch 60/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0033 - categorical_accuracy: 1.0000
    Epoch 61/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0029 - categorical_accuracy: 1.0000
    Epoch 62/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0026 - categorical_accuracy: 1.0000
    Epoch 63/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0025 - categorical_accuracy: 1.0000
    Epoch 64/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0021 - categorical_accuracy: 1.0000
    Epoch 65/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0019 - categorical_accuracy: 1.0000
    Epoch 66/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0016 - categorical_accuracy: 1.0000
    Epoch 67/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0015 - categorical_accuracy: 1.0000
    Epoch 68/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0013 - categorical_accuracy: 1.0000
    Epoch 69/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0013 - categorical_accuracy: 1.0000
    Epoch 70/100
    152/152 [==============================] - 0s 3ms/sample - loss: 0.0011 - categorical_accuracy: 1.0000
    Epoch 71/100
    152/152 [==============================] - 0s 3ms/sample - loss: 9.7354e-04 - categorical_accuracy: 1.0000
    Epoch 72/100
    152/152 [==============================] - 0s 3ms/sample - loss: 8.7477e-04 - categorical_accuracy: 1.0000
    Epoch 73/100
    152/152 [==============================] - 0s 3ms/sample - loss: 7.9792e-04 - categorical_accuracy: 1.0000
    Epoch 74/100
    152/152 [==============================] - 0s 3ms/sample - loss: 7.1617e-04 - categorical_accuracy: 1.0000
    Epoch 75/100
    152/152 [==============================] - 0s 3ms/sample - loss: 6.4143e-04 - categorical_accuracy: 1.0000
    Epoch 76/100
    152/152 [==============================] - 0s 3ms/sample - loss: 5.7778e-04 - categorical_accuracy: 1.0000
    Epoch 77/100
    152/152 [==============================] - 0s 3ms/sample - loss: 5.2867e-04 - categorical_accuracy: 1.0000
    Epoch 78/100
    152/152 [==============================] - 0s 3ms/sample - loss: 4.6775e-04 - categorical_accuracy: 1.0000
    Epoch 79/100
    152/152 [==============================] - 0s 3ms/sample - loss: 4.3156e-04 - categorical_accuracy: 1.0000
    Epoch 80/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.8982e-04 - categorical_accuracy: 1.0000
    Epoch 81/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.5225e-04 - categorical_accuracy: 1.0000
    Epoch 82/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.2291e-04 - categorical_accuracy: 1.0000
    Epoch 83/100
    152/152 [==============================] - 0s 3ms/sample - loss: 3.0208e-04 - categorical_accuracy: 1.0000
    Epoch 84/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.6204e-04 - categorical_accuracy: 1.0000
    Epoch 85/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.3803e-04 - categorical_accuracy: 1.0000
    Epoch 86/100
    152/152 [==============================] - 0s 3ms/sample - loss: 2.1105e-04 - categorical_accuracy: 1.0000
    Epoch 87/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.9740e-04 - categorical_accuracy: 1.0000
    Epoch 88/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.7704e-04 - categorical_accuracy: 1.0000
    Epoch 89/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.6243e-04 - categorical_accuracy: 1.0000
    Epoch 90/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.4778e-04 - categorical_accuracy: 1.0000
    Epoch 91/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.3352e-04 - categorical_accuracy: 1.0000
    Epoch 92/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.2212e-04 - categorical_accuracy: 1.0000
    Epoch 93/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.0887e-04 - categorical_accuracy: 1.0000
    Epoch 94/100
    152/152 [==============================] - 0s 3ms/sample - loss: 1.0243e-04 - categorical_accuracy: 1.0000
    Epoch 95/100
    152/152 [==============================] - 0s 3ms/sample - loss: 9.0790e-05 - categorical_accuracy: 1.0000
    Epoch 96/100
    152/152 [==============================] - 0s 3ms/sample - loss: 8.2472e-05 - categorical_accuracy: 1.0000
    Epoch 97/100
    152/152 [==============================] - 0s 3ms/sample - loss: 7.7913e-05 - categorical_accuracy: 1.0000
    Epoch 98/100
    152/152 [==============================] - 0s 3ms/sample - loss: 6.9800e-05 - categorical_accuracy: 1.0000
    Epoch 99/100
    152/152 [==============================] - 0s 3ms/sample - loss: 6.2189e-05 - categorical_accuracy: 1.0000
    Epoch 100/100
    152/152 [==============================] - 0s 3ms/sample - loss: 5.8351e-05 - categorical_accuracy: 1.0000

```python
# summarize history for loss
plt.plot(history.history['loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['training'], loc='upper left')
plt.show()
```

```python
score = model.evaluate(training,output,verbose=1)
print("Loss:",score[0])
print("Accuracy:",score[1])
```

    Loss: 5.0991909167925386e-05
    Accuracy: 1.0

```python
# save the model .. comment out for now until we train the data appropriately
model.save("model.Chatbot")
```

```python
def bag_of_words(s, words):
    bag = [0 for _ in range(len(words))]

    s_words = nltk.word_tokenize(s)
    s_words = [stemmer.stem(word.lower()) for word in s_words]

    for se in s_words:
        for i, w in enumerate(words):
            if w == se:
                bag[i] = 1

    return numpy.array(bag)

```

```python
def chat():
    print("Start talking with the bot (type quit to stop)!")
    while True:
        inp = input("You: ")
        if inp.lower() == "quit":
            break

        results = model.predict(np.array([bag_of_words(inp, words)]))[0]

        results_index = numpy.argmax(results)
        tag = labels[results_index]
        #print(results[results_index])

        # protect against unknown questions , if model is unsure what user ask they will ask user to rephrase their question
        if results[results_index] > 0.92:   # the value when the model cant recognize is 0.9133338 so i set this value just above it
            for tg in data["intents"]:
                if tg['tag'] == tag:
                    responses = tg['responses']

            print(random.choice(responses))

        else:
            print("I don't understand, please try again or ask a different question :( ")

```

```python
chat()
```

    Start talking with the bot (type quit to stop)!

    You:  hello

    Good to see you again!

    You:  what is your name

    I am the Todd

    You:  what time is it

    One second

    You:  what time do you close

    You may call me Todd

    You:  doyouunderstandthis

    I don't understand, please try again or ask a different question :(

    You:  k

    I don't understand, please try again or ask a different question :(

    You:  s

    I don't understand, please try again or ask a different question :(

    You:  r

    I don't understand, please try again or ask a different question :(

    You:  tell me a joke

    What did the plumber say when he wanted to divorce his wife? Sorry, but it's over, Flo!

    You:  funny joke

    Whizzing round a sharp bend on a country road a motorist ran over a large dog. A distraught farmer's wife ran over to the dead animal. 'I'm so very sorry', said the driver, 'I'll replace him, of course.' 'Well, I don't know', said the farmer's wife, 'Are you any good at catching rats?'

    You:  quit

```python

```

```python

```


```python
!pip install cirq
```

    Collecting cirq
      Downloading cirq-0.14.0-py3-none-any.whl (7.8 kB)
    Collecting cirq-web==0.14.0
      Downloading cirq_web-0.14.0-py3-none-any.whl (593 kB)
    Collecting cirq-pasqal==0.14.0
      Downloading cirq_pasqal-0.14.0-py3-none-any.whl (30 kB)
    Collecting cirq-ionq==0.14.0
      Downloading cirq_ionq-0.14.0-py3-none-any.whl (48 kB)
    Collecting cirq-rigetti==0.14.0
      Downloading cirq_rigetti-0.14.0-py3-none-any.whl (56 kB)
    Collecting cirq-core==0.14.0
      Downloading cirq_core-0.14.0-py3-none-any.whl (1.8 MB)
    Collecting cirq-aqt==0.14.0
      Downloading cirq_aqt-0.14.0-py3-none-any.whl (19 kB)
    Collecting cirq-google==0.14.0
      Downloading cirq_google-0.14.0-py3-none-any.whl (541 kB)
    Requirement already satisfied: requests~=2.18 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-aqt==0.14.0->cirq) (2.25.1)
    Requirement already satisfied: sortedcontainers~=2.0 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (2.3.0)
    Requirement already satisfied: typing-extensions in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (3.7.4.3)
    Requirement already satisfied: scipy in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (1.6.2)
    Requirement already satisfied: matplotlib~=3.0 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (3.3.4)
    Requirement already satisfied: networkx~=2.4 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (2.5)
    Requirement already satisfied: sympy<1.10 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (1.8)
    Requirement already satisfied: pandas in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (1.2.4)
    Requirement already satisfied: tqdm in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (4.59.0)
    Collecting duet~=0.2.0
      Downloading duet-0.2.5-py3-none-any.whl (28 kB)
    Requirement already satisfied: numpy~=1.16 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-core==0.14.0->cirq) (1.20.1)
    Collecting google-api-core[grpc]<2.0.0dev,>=1.14.0
      Downloading google_api_core-1.31.5-py2.py3-none-any.whl (93 kB)
    Requirement already satisfied: protobuf>=3.13.0 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-google==0.14.0->cirq) (3.19.4)
    Collecting httpx~=0.15.5
      Downloading httpx-0.15.5-py3-none-any.whl (65 kB)
    Requirement already satisfied: attrs~=20.3.0 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-rigetti==0.14.0->cirq) (20.3.0)
    Collecting rfc3986~=1.5.0
      Downloading rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)
    Requirement already satisfied: toml~=0.10.2 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-rigetti==0.14.0->cirq) (0.10.2)
    Collecting certifi~=2021.5.30
      Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
    Requirement already satisfied: python-dateutil~=2.8.1 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-rigetti==0.14.0->cirq) (2.8.1)
    Collecting iso8601~=0.1.14
      Downloading iso8601-0.1.16-py2.py3-none-any.whl (10 kB)
    Collecting six~=1.16.0
      Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
    Collecting httpcore~=0.11.1
      Downloading httpcore-0.11.1-py3-none-any.whl (52 kB)
    Collecting pyjwt~=1.7.1
      Using cached PyJWT-1.7.1-py2.py3-none-any.whl (18 kB)
    Requirement already satisfied: idna~=2.10 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-rigetti==0.14.0->cirq) (2.10)
    Collecting retrying~=1.3.3
      Downloading retrying-1.3.3.tar.gz (10 kB)
    Requirement already satisfied: sniffio~=1.2.0 in c:\users\ameyb\anaconda3\lib\site-packages (from cirq-rigetti==0.14.0->cirq) (1.2.0)
    Collecting rfc3339~=6.2
      Downloading rfc3339-6.2-py3-none-any.whl (5.5 kB)
    Collecting pydantic~=1.8.2
      Downloading pydantic-1.8.2-cp38-cp38-win_amd64.whl (2.0 MB)
    Collecting pyquil~=3.0.0
      Downloading pyquil-3.0.1-py3-none-any.whl (220 kB)
    Collecting qcs-api-client~=0.8.0
      Downloading qcs_api_client-0.8.0-py3-none-any.whl (97 kB)
    Collecting h11~=0.9.0
      Downloading h11-0.9.0-py2.py3-none-any.whl (53 kB)
    Collecting googleapis-common-protos<2.0dev,>=1.6.0
      Downloading googleapis_common_protos-1.56.0-py2.py3-none-any.whl (241 kB)
    Collecting google-auth<2.0dev,>=1.25.0
      Downloading google_auth-1.35.0-py2.py3-none-any.whl (152 kB)
    Requirement already satisfied: pytz in c:\users\ameyb\anaconda3\lib\site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (2021.1)
    Requirement already satisfied: packaging>=14.3 in c:\users\ameyb\anaconda3\lib\site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (20.9)
    Requirement already satisfied: setuptools>=40.3.0 in c:\users\ameyb\anaconda3\lib\site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (52.0.0.post20210125)
    Requirement already satisfied: grpcio<2.0dev,>=1.29.0 in c:\users\ameyb\anaconda3\lib\site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (1.44.0)
    Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\users\ameyb\anaconda3\lib\site-packages (from google-auth<2.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (0.2.8)
    Collecting cachetools<5.0,>=2.0.0
      Downloading cachetools-4.2.4-py3-none-any.whl (10 kB)
    Requirement already satisfied: rsa<5,>=3.1.4 in c:\users\ameyb\anaconda3\lib\site-packages (from google-auth<2.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (4.8)
    Requirement already satisfied: cycler>=0.10 in c:\users\ameyb\anaconda3\lib\site-packages (from matplotlib~=3.0->cirq-core==0.14.0->cirq) (0.10.0)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in c:\users\ameyb\anaconda3\lib\site-packages (from matplotlib~=3.0->cirq-core==0.14.0->cirq) (2.4.7)
    Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\ameyb\anaconda3\lib\site-packages (from matplotlib~=3.0->cirq-core==0.14.0->cirq) (1.3.1)
    Requirement already satisfied: pillow>=6.2.0 in c:\users\ameyb\anaconda3\lib\site-packages (from matplotlib~=3.0->cirq-core==0.14.0->cirq) (8.2.0)
    Requirement already satisfied: decorator>=4.3.0 in c:\users\ameyb\anaconda3\lib\site-packages (from networkx~=2.4->cirq-core==0.14.0->cirq) (5.0.6)
    Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\users\ameyb\anaconda3\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<2.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google==0.14.0->cirq) (0.4.8)
    Collecting lark<0.12.0,>=0.11.1
      Downloading lark-0.11.3.tar.gz (229 kB)
    Collecting rpcq<4.0.0,>=3.6.0
      Downloading rpcq-3.9.2.tar.gz (43 kB)
    Collecting retry<0.10.0,>=0.9.2
      Downloading retry-0.9.2-py2.py3-none-any.whl (8.0 kB)
    Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\ameyb\anaconda3\lib\site-packages (from requests~=2.18->cirq-aqt==0.14.0->cirq) (1.26.4)
    Requirement already satisfied: chardet<5,>=3.0.2 in c:\users\ameyb\anaconda3\lib\site-packages (from requests~=2.18->cirq-aqt==0.14.0->cirq) (4.0.0)
    Requirement already satisfied: py<2.0.0,>=1.4.26 in c:\users\ameyb\anaconda3\lib\site-packages (from retry<0.10.0,>=0.9.2->pyquil~=3.0.0->cirq-rigetti==0.14.0->cirq) (1.10.0)
    Collecting msgpack<1.0,>=0.6
      Downloading msgpack-0.6.2.tar.gz (119 kB)
    Collecting python-rapidjson
      Downloading python_rapidjson-1.6-cp38-cp38-win_amd64.whl (143 kB)
    Requirement already satisfied: pyzmq>=17 in c:\users\ameyb\anaconda3\lib\site-packages (from rpcq<4.0.0,>=3.6.0->pyquil~=3.0.0->cirq-rigetti==0.14.0->cirq) (20.0.0)
    Collecting ruamel.yaml
      Downloading ruamel.yaml-0.17.21-py3-none-any.whl (109 kB)
    Requirement already satisfied: mpmath>=0.19 in c:\users\ameyb\anaconda3\lib\site-packages (from sympy<1.10->cirq-core==0.14.0->cirq) (1.2.1)
    Collecting ruamel.yaml.clib>=0.2.6
      Downloading ruamel.yaml.clib-0.2.6-cp38-cp38-win_amd64.whl (117 kB)
    Building wheels for collected packages: lark, retrying, rpcq, msgpack
      Building wheel for lark (setup.py): started
      Building wheel for lark (setup.py): finished with status 'done'
      Created wheel for lark: filename=lark-0.11.3-py2.py3-none-any.whl size=99635 sha256=155e7e2100b52b4d75f8b42f117bb6698394e89cd998645896af53ed1a02d1ba
      Stored in directory: c:\users\ameyb\appdata\local\pip\cache\wheels\34\cb\6c\4df359c2a3f0a1af4cccae6392bee423bb5aff530103de3538
      Building wheel for retrying (setup.py): started
      Building wheel for retrying (setup.py): finished with status 'done'
      Created wheel for retrying: filename=retrying-1.3.3-py3-none-any.whl size=11429 sha256=e25e954dd607b67304a1195b8285ae5e67180926f92f23e8530da1a489c1c5bd
      Stored in directory: c:\users\ameyb\appdata\local\pip\cache\wheels\c4\a7\48\0a434133f6d56e878ca511c0e6c38326907c0792f67b476e56
      Building wheel for rpcq (setup.py): started
      Building wheel for rpcq (setup.py): finished with status 'done'
      Created wheel for rpcq: filename=rpcq-3.9.2-py3-none-any.whl size=45865 sha256=74d9bce012f3f24fc0fe440ee93502f2efd71bd8bc10324efde8e15d89af21f1
      Stored in directory: c:\users\ameyb\appdata\local\pip\cache\wheels\20\fd\8d\4d4a9f389a9c92210dbee8ca8bbd725a6204f64a8ca8cad841
      Building wheel for msgpack (setup.py): started
      Building wheel for msgpack (setup.py): finished with status 'done'
      Created wheel for msgpack: filename=msgpack-0.6.2-cp38-cp38-win_amd64.whl size=73428 sha256=c9451975d58a7a983fc5b1ef7e660a774c871f8f4f2d6373645cdba003b70589
      Stored in directory: c:\users\ameyb\appdata\local\pip\cache\wheels\5d\f2\04\0d19c10080b996bef17c908a6243e6e65d8da1a4094a3f604d
    Successfully built lark retrying rpcq msgpack
    Installing collected packages: rfc3986, h11, six, ruamel.yaml.clib, httpcore, certifi, cachetools, ruamel.yaml, rfc3339, retrying, python-rapidjson, pyjwt, pydantic, msgpack, iso8601, httpx, googleapis-common-protos, google-auth, rpcq, retry, qcs-api-client, lark, google-api-core, duet, pyquil, cirq-core, cirq-web, cirq-rigetti, cirq-pasqal, cirq-ionq, cirq-google, cirq-aqt, cirq
      Attempting uninstall: six
        Found existing installation: six 1.15.0
        Uninstalling six-1.15.0:
          Successfully uninstalled six-1.15.0
      Attempting uninstall: certifi
        Found existing installation: certifi 2020.12.5
        Uninstalling certifi-2020.12.5:
          Successfully uninstalled certifi-2020.12.5
      Attempting uninstall: cachetools
        Found existing installation: cachetools 5.0.0
        Uninstalling cachetools-5.0.0:
          Successfully uninstalled cachetools-5.0.0
      Attempting uninstall: msgpack
        Found existing installation: msgpack 1.0.2
        Uninstalling msgpack-1.0.2:
          Successfully uninstalled msgpack-1.0.2
      Attempting uninstall: google-auth
        Found existing installation: google-auth 2.6.2
        Uninstalling google-auth-2.6.2:
          Successfully uninstalled google-auth-2.6.2
    Successfully installed cachetools-4.2.4 certifi-2021.5.30 cirq-0.14.0 cirq-aqt-0.14.0 cirq-core-0.14.0 cirq-google-0.14.0 cirq-ionq-0.14.0 cirq-pasqal-0.14.0 cirq-rigetti-0.14.0 cirq-web-0.14.0 duet-0.2.5 google-api-core-1.31.5 google-auth-1.35.0 googleapis-common-protos-1.56.0 h11-0.9.0 httpcore-0.11.1 httpx-0.15.5 iso8601-0.1.16 lark-0.11.3 msgpack-0.6.2 pydantic-1.8.2 pyjwt-1.7.1 pyquil-3.0.1 python-rapidjson-1.6 qcs-api-client-0.8.0 retry-0.9.2 retrying-1.3.3 rfc3339-6.2 rfc3986-1.5.0 rpcq-3.9.2 ruamel.yaml-0.17.21 ruamel.yaml.clib-0.2.6 six-1.16.0

    ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
    conda-repo-cli 1.0.4 requires pathlib, which is not installed.

```python
import tensorflow as tf
import numpy as np
import cirq

%matplotlib inline
import matplotlib.pyplot as plt

from cirq.contrib.svg import SVGCircuit
```

## Part 1

```python
#qubits = cirq.GridQubit.rect(1,5)
circuit = cirq.Circuit()

circuit.append((cirq.H(i)) for i in cirq.LineQubit.range(5))
for i in cirq.LineQubit.range(4):
    circuit.append(cirq.CNOT(control=i , target = i+1))
circuit.append(cirq.SWAP(cirq.LineQubit(0),cirq.LineQubit(4)))
circuit.append(cirq.rx(np.pi/2).on(cirq.LineQubit(np.random.randint(5))))
SVGCircuit(circuit)
```

## Part 2

```python
circuit = cirq.Circuit()
qubit=cirq.LineQubit(0)
angle = np.random.random(5)/20
for i in range(5):
    circuit.append(cirq.rx(angle[i]).on(qubit))
circuit.append(cirq.measure(qubit,key='result'))
SVGCircuit(circuit)

```

```python
simulator = cirq.Simulator()
samples = simulator.run(circuit, repetitions=1024)
hist_data = samples.measurements['result'].reshape(1024,)
print('The probability of measuring a qubit in |0> state : ', samples.histogram(key='result')[0]/1024)
print(samples.histogram(key='result'))
plt.hist(hist_data)
```

```python

```