{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "aHyU81dQ-t7Q",
        "outputId": "6253822c-a967-492e-acb3-a6f053000f0b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Apple 4 9 ORG\n",
            "U.K. 31 35 GPE\n",
            "$1 billion 48 58 MONEY\n"
          ]
        }
      ],
      "source": [
        "import spacy\n",
        "nlp = spacy.load('en_core_web_sm')\n",
        "sentence = \"Why Apple is looking at buying U.K. startup for $1 billion ?\"\n",
        "doc = nlp(sentence)\n",
        "\n",
        "for ent in doc.ents:\n",
        "    print(ent.text, ent.start_char, ent.end_char, ent.label_)\n"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "sentence = \"Why apple is now looking at buying U.K. startup for $1 billion ?\"\n",
        "doc = nlp(sentence)\n",
        "\n",
        "for ent in doc.ents:\n",
        "    print(ent.text, ent.start_char, ent.end_char, ent.label_)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "reroi21_-ydg",
        "outputId": "f01ffb0a-9969-4b79-f135-b6be3e119227"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "U.K. 35 39 GPE\n",
            "$1 billion 52 62 MONEY\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from spacy.tokens import Span\n",
        "doc = nlp(\"Tesla is planning to launch a new product.\")\n",
        "\n",
        "custom_label = \"ORG\"\n",
        "doc.ents = (Span(doc, 0, 1, label=custom_label),)\n",
        "\n",
        "for ent in doc.ents:\n",
        "    print(ent.text, ent.label_)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "78rSl6NzAZKE",
        "outputId": "bdb0c0a2-c1e4-4b1f-b36c-9797b699f9c3"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Tesla ORG\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "Y1Gk0gQXAhdX"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}