# NLP

<details>

<summary>[OKCUPID] Term Frequency</summary>

Say you are given a text document in the form of a string with the following sentences:

**Input**

`document = "I have a nice car with a nice tires"`

**Output**

`{ "I":0.11, "have":0.11, "a":0.22, "nice":0.22, "car": 0.11, "with":0.11, "tires":0.11 }`&#x20;

Write a program in python to determine the TF (term frequency) values for each term of this document.

**Answer**

{% code overflow="wrap" %}

```python
# term freq = freq of term 't' in doc 'd' / total terms in 'd'

def tf(doc):
    temp_list = doc.split(" ") # split terms
    final_dict = {} # store final dictionary with term freq
    for i in temp_list:
        if i not in final_dict.keys(): # check if term is already present in dict
            final_dict[i] = round(temp_list.count(i)/len(temp_list),2) # calculating tf
    return final_dict

tf("I have a nice car with a nice tires")
```

{% endcode %}

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.thedatascienceinterviewproject.com/python/nlp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
