<jupyter_start><jupyter_text>![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/streamlit_notebooks/NER_RESTAURANT.ipynb)  **Ner_Restaurant**  1. Colab Setup<jupyter_code># Install PySpark and Spark NLP
! pip install -q pyspark==3.1.2 spark-nlp

# Install Spark NLP Display lib
! pip install --upgrade -q spark-nlp-display
import json
import pandas as pd
import numpy as np

from pyspark.ml import Pipeline
from pyspark.sql import SparkSession
import pyspark.sql.functions as F
from sparknlp.annotator import *
from sparknlp.base import *
import sparknlp
from sparknlp.pretrained import PretrainedPipeline

spark = sparknlp.start()<jupyter_output><empty_output><jupyter_text>2. Some sample examples<jupyter_code>text_list_restaurant = ["""Noma is located on the north side of the city. The restaurant has a cuisine based solely on ingredients found in the area. These days, \
dinner may begin with potato pie and fresh fruit juice. The meal can then continue with traditional Danish pastry. \
This wonderful borek is brushed with a garlic sauce and finished with almond, hazelnut and plum puree.It sounds wacky, but somehow crew \
manage to make it all delicious.It also has the feature of being a vegan restaurant. I think it deserves 5 stars.The price of a meal for two is \
very reasonable for this taste. The restaurant, which is open until 2 am, is always very crowded.""",


"""This restaurant,  favorite pasta bar also offers one of the most reasonably priced lunch sets in town! With locations spread out all over \
the territory Sha Tin – Pici’s formidable lunch menu reads like a highlight reel of the restaurant. Choose from starters like the burrata and \
arugula salad or freshly tossed tuna tartare, and reliable handmade pasta dishes like pappardelle. Finally, round out your effortless Italian \
meal with a tidy one-pot tiramisu, of course, an espresso to power you through the rest of the day.""",


"""My favorite dish at the Oceandelf Restaurant, was shrimp and grits topped with a tasty tasso sauce and loaded with locally netted Georgia \
white shrimp. The chef and his staff are staunch advocates of the farm-to-table concept, sourcing produce, meats,poultry and dairy products \
almost exclusively from Georgia organic farms.They offer a wide array of fresh food – green pork plate, hamburger, barbacoa plate,  bbq with \
rice and beans and more.They can be one of the best representatives of Georgian cuisine. They prefer the freshest ingredients when preparing \
their meals to ensure the best quality and taste. Its prices are very affordable compared to almost other places, it appeals to everyone.Since \
they are open until 11 pm, they are a great alternative for late evening meals.""",


"""Ahloven Restaurant opened near North Avenue in 2000. I visited for lunch with a friend. We enjoyed the authentic South Indian main courses. \
The menu was good. The brownie after the meal was very good.The service was above average but the fries were too flavorless to finish. For  \
15 dollars the quality should have been much higher. When the waiter came to our table and asked if we wanted anything, we explained that \
we didn't like the french fries. He was understanding and offered us a discount on the fries.""",


"""Mcdills restaurant is situated in the heart of a semi-urban area near a motorsports academy. It is possible to find fresh and tasty food \
every hour in the restaurant, which is open until 3 am. The menu offers a wide variety of delicious. I had smoked salmon with horseradish cream, \
as well as prawns and lime vinaigrette. My friend tried the triple cheese and tarragon-stuffed mushrooms. They were all exquisite.The main course \
included a fantastic veggie shepherd’s pie with sweet potato mash and creamy courgette lasagne. It was all followed by a savory apple pie with \
a chocolate. Everything we ate was fresh and delicious. The award-winning chefs use the best quality ingredients to produce dishes that are simply \
delightful. The restaurant also offers  a wonderful drink menu, and they offer one of the best wines in the region. In contrast, however, the \
service was not of the highest quality. It seemed to me that the waiters were not very engaged or interested in their jobs.He came around to \
check on our experience and seemed to be authentically engaged.Prices are quite expensive compared to other places."""]<jupyter_output><empty_output><jupyter_text>3. Define Spark NLP pipeline<jupyter_code>document = DocumentAssembler()\
  .setInputCol("text")\
  .setOutputCol("document")

sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl", "en")\
  .setInputCols(["document"])\
  .setOutputCol("sentence")

tokenizer = Tokenizer()\
  .setInputCols("sentence")\
  .setOutputCol("token")  

embeddings = WordEmbeddingsModel.pretrained("glove_100d")\
  .setInputCols("sentence", "token") \
  .setOutputCol("embeddings")

nerdl = NerDLModel.pretrained("nerdl_restaurant_100d")\
  .setInputCols(["sentence", "token", "embeddings"])\
  .setOutputCol("ner")

ner_converter = NerConverter()\
  .setInputCols(["sentence", "token", "ner"])\
  .setOutputCol("ner_chunk")

pipeline = Pipeline(stages=[document,
                            sentenceDetector,
                            tokenizer,
                            embeddings, 
                            nerdl, 
                            ner_converter])


empty_data = spark.createDataFrame([[""]]).toDF("text")
model = pipeline.fit(empty_data)<jupyter_output>sentence_detector_dl download started this may take some time.
Approximate size to download 354.6 KB
[OK!]
glove_100d download started this may take some time.
Approximate size to download 145.3 MB
[OK!]
nerdl_restaurant_100d download started this may take some time.
Approximate size to download 13.6 MB
[OK!]<jupyter_text>4. Visualize results<jupyter_code>df = spark.createDataFrame(pd.DataFrame({"text":text_list_restaurant}))
result = model.transform(df)
from sparknlp_display import NerVisualizer

for i in range(len(text_list_restaurant)):
  NerVisualizer().display(
      result = result.collect()[i],
      label_col = 'ner_chunk',
      document_col = 'document'
  )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07283526101906845, 'fraction_numerical': 0.006408252578930916, 'mean_word_length': 4.3325, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '269792', 'license': 'Apache-2.0', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1745, 'n_words': 773, 'path': 'tutorials/streamlit_notebooks/NER_RESTAURANT.ipynb', 'repo_name': 'fcivardi/spark-nlp-workshop', 'size': '6398'}