Spaces:
Sleeping
Sleeping
Download keyword_extraction.py from EE21/ToS-Summarization: direct link, hf CLI and curl.
- Browser
- Download file 503 Bytes
-
https://huggingface.co/spaces/EE21/ToS-Summarization/resolve/main/keyword_extraction.py
- Command line
-
hf download hf://spaces/EE21/ToS-Summarization/keyword_extraction.py
-
curl -L -o keyword_extraction.py https://huggingface.co/spaces/EE21/ToS-Summarization/resolve/main/keyword_extraction.py
503 Bytes
| import nltk | |
| from rake_nltk import Rake | |
| # Download NLTK data (if not already downloaded) | |
| nltk.download('punkt') | |
| nltk.download('stopwords') | |
| def extract_keywords(text): | |
| # Initialize Rake with stopwords set to None (to keep all words) | |
| rake = Rake(max_length=2, include_repeated_phrases=False) | |
| # Extract keywords from the input text | |
| rake.extract_keywords_from_text(text) | |
| # Get the ranked keywords | |
| ranked_keywords = rake.get_ranked_phrases() | |
| return ranked_keywords |