semvec/pypi-packages huggingface dataset:
labelled-topic-clustering 1.1.0
Super Simple Labelled Topic Clustering
License: MIT
Requires Python: >=3.9
Keywords: Sentence, Topic, Clustering, Labelling, Cosine Similarity, LDA, HuggingFace, pyTorch, Spacy, NLP, Deep Learning


# Labelled Topic Clustering

Labelled Topic Clustering is as the name suggests, feed it an array of sentences and it will cluster them with human-readable names.

The aim of this project is to make it as **easy-as-possible** to:

1. generate topic clusters on a text dataset using a cosine-similarity approach.
2. get human-readable labels for those clusters

![labelled topic clustering approach](https://github.com/tomhaydn/labelled-topic-clustering/blob/main/docs/diagram-1.png)

## Installation

To use the TopicClusterer class, you need to install the required packages. Assuming you have a package manager like pip, you can install the dependencies as follows:

`pip install labelled-topic-clustering`

## Usage

1. Initialize the TopicClusterer:

```
from topic_clusterer import TopicClusterer

hf_token = "your_hugging_face_token"
# This can be any sentence-transformer, anecdotally I've found this the best.
model = "sentence-transformers/all-mpnet-base-v2"

clusterer = TopicClusterer(hf_token, model, debug=True)
```

2. Get clusters:

```
sentences = [
    "the weather is great",
    "This is some perfect weather",
    "we're having some really good weather",
    "my dog ate my homework",
    "why do dogs love homework?",
    "dog keeps devouring my homework"
]

clusters = clusterer.get_clusters(sentences)
```

#### Example Output

```
[[0, 1, 2], [3, 4, 5]]
```

`clusters` will be a 2d array representing clusters with sentence indicies for the original dataset

3. Get labels from clusters:

```
clusters_labelled = clusterer.get_labels_from_clusters(clusters, sentences)
```

#### Example Output

```
{'Weather great perfect': [0, 1, 2], 'Dog eat homework': [3, 4, 5]}
```

`clusters_labelled` is a dictionary where the keys are topic labels, and the values are arrays of sentence indices corresponding to the original dataset.

> You can also just get it all at once:

```
# Get clusters with labels
labelled_clusters = clusterer.get_clusters_with_labels(sentences)
print(labelled_clusters)
```

# Contributing

You can view all the info on development and contributing [here](./CONTRIBUTING.md)

# Looking Forward

I have done virtually no performance testing as I wrote this once and it was all I needed for a side project.

Some ideas to work on:

- Allow custom tokenizers
- Benchmark performance on large datasets
- Allow for feature extraction locally
google-opensearch-api 1.0.13
Python library for fetching and parsing Google search results.
License: MIT
Requires Python: >=3.6

# Google Open Search API Python Module

## Overview

The **Google Search API Python Module** is a Python library that allows you to fetch and parse Google search results programmatically. It provides an easy-to-use interface to perform Google searches and retrieve search result data such as titles, URLs, snippets, and displayed links.

## Installation

You can install the `google-opensearch-api` module using pip:

```bash
pip install google-opensearch-api
```

## Usage

### Basic Example

```python
from google_search_api.google_search_api import GoogleSearchAPI

# Initialize GoogleSearchAPI object
google_search_api = GoogleSearchAPI()

# Perform a Google search
query = "Cyber Security"
num_results = 10
search_results = google_search_api.google_search(query, num_results)

# Print search results in JSON format
print(search_results)
```

## Advanced Usage
### Parameters
- `query` (str): The search query to be performed.
- `num_results` (int, optional): Number of search results to retrieve (default is 10).

### CLI Usage

You can use the `google-opensearch` command line tool to perform Google searches:
```python
google-search "cyber security" --num_results 5
```
### Docker Container Usage

You can use the `google-opensearch-api` Docker container to perform Google searches:

```cmd
docker run -it --rm google-opensearch-api "cyber security" --num_results 5
```

### Output

The `google_search` method returns a JSON string containing search results and metadata:

```json
{
    "metadata": {
        "num_requested": 10,
        "total_items_fetched": 10,
        "runtime_seconds": 1.234
    },
    "results": [
        {
            "id": 1,
            "title": "Example Result Title",
            "link": "https://example.com",
            "snippet": "Example result snippet text.",
            "displayed_link": "example.com"
        },
        {
            "id": 2,
            "title": "Another Result Title",
            "link": "https://another-example.com",
            "snippet": "Another result snippet.",
            "displayed_link": "another-example.com"
        },
        ...
    ]
}
```

### Notes
- Duplicates: The module automatically removes duplicate URLs from the search results.
- Snippet: Snippet text may not be available for all results depending on Google's HTML structure.

## Contributing
Contributions to the google-search-api module are welcome! You can contribute by forking the repository, making changes, and submitting a pull request.

## License
The google-search-api module is licensed under the MIT license.

## Support
For any issues or questions related to the google-search-api module, please open an issue on GitHub.

## Acknowledgments
- The google-search-api module utilizes requests and beautifulsoup4 libraries for web scraping and parsing HTML.
- This module was inspired by the Google Search API.

Authors
- CuriousTinker - https://github.com/CuriousTinker

Changelog
- v1.0.0 (2024-06-15)
    - Initial release of the google-search-api module.