Saturday, February 12, 2022

Chatbot using Rasa


references:

https://www.geeksforgeeks.org/chatbots-using-python-and-rasa/#:~:text=Rasa%20is%20a%20tool%20to,model%20and%20add%20custom%20actions.

Tuesday, February 8, 2022

Numpy dimension, shape, axeses

First:

By convention, in Python world, the shortcut for numpy is np, so:


In [1]: import numpy as np


In [2]: a = np.array([[1,2],[3,4]])


Second:

In Numpy, dimension, axis/axes, shape are related and sometimes similar concepts:


dimension

In Mathematics/Physics, dimension or dimensionality is informally defined as the minimum number of coordinates needed to specify any point within a space. But in Numpy, according to the numpy doc, it's the same as axis/axes:


In Numpy dimensions are called axes. The number of axes is rank.


In [3]: a.ndim  # num of dimensions/axes, *Mathematics definition of dimension*

Out[3]: 2


axis/axes

the nth coordinate to index an array in Numpy. And multidimensional arrays can have one index per axis.


In [4]: a[1,0]  # to index `a`, we specific 1 at the first axis and 0 at the second axis.

Out[4]: 3  # which results in 3 (locate at the row 1 and column 0, 0-based index)


First:

By convention, in Python world, the shortcut for numpy is np, so:


In [1]: import numpy as np


In [2]: a = np.array([[1,2],[3,4]])

Second:

In Numpy, dimension, axis/axes, shape are related and sometimes similar concepts:


dimension

In Mathematics/Physics, dimension or dimensionality is informally defined as the minimum number of coordinates needed to specify any point within a space. But in Numpy, according to the numpy doc, it's the same as axis/axes:


In Numpy dimensions are called axes. The number of axes is rank.


In [3]: a.ndim  # num of dimensions/axes, *Mathematics definition of dimension*

Out[3]: 2

axis/axes

the nth coordinate to index an array in Numpy. And multidimensional arrays can have one index per axis.


In [4]: a[1,0]  # to index `a`, we specific 1 at the first axis and 0 at the second axis.

Out[4]: 3  # which results in 3 (locate at the row 1 and column 0, 0-based index)

shape

describes how many data (or the range) along each available axis.


In [5]: a.shape

Out[5]: (2, 2)  # both the first and second axis have 2 (columns/rows/pages/blocks/...) data




import numpy as np   

>>> np.shape(a)

(2,2)


Also works if the input is not a numpy array but a list of lists



>>> a = [[1,2],[1,2]]

>>> np.shape(a)

(2,2)


Or a tuple of tuples


>>> a = ((1,2),(1,2))

>>> np.shape(a)

(2,2)


np.shape first turns its argument into an array if it doesn't have the shape attribute, That's why it works on the list and tuple examples. 



References:

https://stackoverflow.com/questions/3061761/numpy-array-dimensions

numpy cheatsheet

 https://cheatography.com/mdesai96/cheat-sheets/numpy-cheat-sheet/

Why Numpy arrays are faster

 Numpy arrays are densely packed arrays of homogeneous type. Python lists, by contrast, are arrays of pointers to objects, even when all of them are of the same type. So, you get the benefits of locality of reference.


Also, many Numpy operations are implemented in C, avoiding the general cost of loops in Python, pointer indirection and per-element dynamic type checking. The speed boost depends on which operations you're performing, but a few orders of magnitude isn't uncommon in number crunching programs.

Saturday, February 5, 2022

WhatsApp Business API

The WhatsApp Business API is a fast, secure, and reliable way for businesses to reach their customers all over the world


The WhatsApp Business API client supports a subset of the features provided by the WhatsApp applications you already know from Android, iOS, and the web, including end-to-end encryption. The difference is that this application can be deployed on a server, providing a local API that allows you to programmatically send and receive messages and integrate this workflow with your own systems (e.g., CRMs, contact center platforms, etc.).


Please note that if you use anything other than the official WhatsApp Business API or other official WhatsApp tools, we reserve the right to limit or remove your access to WhatsApp as this violates our policies. Please do not use any non-WhatsApp authorized third-party tools to communicate on WhatsApp.


Business Solution Providers

If you are looking to get started with the WhatsApp Business API right away, we have partnered with a group of third-party business solution providers (BSPs) that can help you with setup and integration. Browse the Partner Directory to find the partners that suit your needs.


How It Works


The first step for businesses to communicate with customers on WhatsApp is to create a WhatsApp business account and set up a line of credit. This business account will allow people to easily identify your business and find out more information such as your address, hours of operation, website, and description. Through your account in the Facebook Business Manager you will have the ability to create message templates for sending notifications to customers at scale.


WhatsApp message templates and media message templates are specific message formats that businesses use to send out notifications or customer care messages to people that have opted in to notifications. Messages can include appointment reminders, shipping information, issue resolution and payment updates. These are the preferred method of reaching customers.


Other types of messages such as text and media, must be sent within a 24-hour window of a message from a customer.



references:

https://developers.facebook.com/docs/whatsapp

Thursday, February 3, 2022

What is SQuAD

 The Stanford Question Answering Dataset (SQuAD) is a set of question and answer pairs that present a strong challenge for NLP models. Whether you’re just interested in learning about a popular NLP dataset or planning to use it in one of your projects, here are all the basics you should know.


What task does SQuAD present? As implied by its name, SQuAD focuses on the task of question answering. It tests a model’s ability to read a passage of text and then answer questions about it (flashback to reading comprehension on the SAT). It’s a relatively straightforward task; here’s an example that the dataset’s creators gave:


How was SQuAD created? To compile SQuAD, the creators sampled 536 from the top 10,000 Wikipedia articles. From each of these sampled articles, they extracted a total of 23,215 individual paragraphs (making sure to filter for paragraphs that were too small). They split the dataset by articles such that 80% of articles went into the training set, 10% into a development set, and 10% into a testing set.


Annotating SQuAD. The most important part of creating a dataset — annotating it — was done by Mechanical Turk workers. Classic! I’m seeing Mechanical Turk making a cameo in a lot of these NLP papers. These workers were selected only if they had a history of high quality work (as measured by the HIT approval rate). For each selected paragraph, the workers were asked to come up with and answer 5 questions on the content of the paragraph. They were provided a text field to type their question, and they could highlight the answers in the paragraph. The creators of SQuAD made sure that the questions that the workers came up with were in their own words, even disabling the copy-paste functionality. Noooooo! Not my copy-paste tools!



References:

https://towardsdatascience.com/the-quick-guide-to-squad-cae08047ebee#:~:text=Oct%208%2C%202020%C2%B74%20min,the%20basics%20you%20should%20know.

What is BERT

BERT (Bidirectional Encoder Representations from Transformers) is a recent paper published by researchers at Google AI Language. It has caused a stir in the Machine Learning community by presenting state-of-the-art results in a wide variety of NLP tasks, including Question Answering (SQuAD v1.1), Natural Language Inference (MNLI), and others.

BERT’s key technical innovation is applying the bidirectional training of Transformer, a popular attention model, to language modelling. This is in contrast to previous efforts which looked at a text sequence either from left to right or combined left-to-right and right-to-left training. The paper’s results show that a language model which is bidirectionally trained can have a deeper sense of language context and flow than single-direction language models. In the paper, the researchers detail a novel technique named Masked LM (MLM) which allows bidirectional training in models in which it was previously impossible.

References:

https://towardsdatascience.com/bert-explained-state-of-the-art-language-model-for-nlp-f8b21a9b6270