Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

NLP text summarization preprocess and tokenization

import pandas as pd
import numpy as np
data = "my name is shubham kumar shukla. It is my pleasure to got opportunity to write article for xyz related to nlp"
from nltk.tokenize
import word_tokenize, sent_tokenize
from nltk.corpus
import stopwords
def solve(text):
  stopwords1 = set(stopwords.words("english"))
words = word_tokenize(text)
freqTable = {}
for word in words:
  word = word.lower()
if word in stopwords1:
  continue
if word in freqTable:
  freqTable[word] += 1
else :
  freqTable[word] = 1

sentences = sent_tokenize(text)
sentenceValue = {}
for sentence in sentences:
  for word, freq in freqTable.items():
  if word in sentence.lower():
  if sentence in sentenceValue:
  sentenceValue[sentence] += freq
else :
  sentenceValue[sentence] = freq
sumValues = 0
for sentence in sentenceValue:
  sumValues += sentenceValue[sentence]
average = int(sumValues / len(sentenceValue))

summary = ''
for sentence in sentences:
  if (sentence in sentenceValue) and(sentenceValue[sentence] > (1.2 * average)):
    summary += "" + sentence
return summary
Comment

PREVIOUS NEXT
Code Example
Python :: Python RegEx Split – re.split() Syntax 
Python :: Connection to Python debugger failed: Interrupted function call: accept failed 
Python :: different accuracy score for knn 
Python :: python regular expression path 
Python :: python interate with two list 
Python :: ABA Alphabet pyramid 
Python :: sorting list of strings by length python 
Python :: web3.eth.personal.newAccount(password, [callback]) 
Python :: python4 
Python :: unittest only run test if other tests passes 
Python :: how to make change the default from python 3.8 to python 3.10.5 on Mint 20 
Python :: how to calculate the area and perimeter of a shape in python 
Python :: How to use a function output as an input of another function in Python 
Python :: how to choose appropriate graph for your dataset visualization 
Python :: change dimension position of numpy array 
Python :: Collecting package metadata (repodata.json): done Solving environment: failed ResolvePackageNotFound: - python==3.9.13 
Python :: how to have unlimited parameters in a function in python 
Python :: run thread that inputs into queue and other threads process that python 
Python :: new library in python3 
Python :: crank nicholson scheme python 
Python :: trends in yearly data python 
Python :: hwoto neglect if any exception happening in python 
Python :: hms bagle 
Python :: k means image classification 
Python :: java sript 
Python :: quando è stata inventata la lavastoviglie 
Python :: how to take long input in python 
Python :: Return a new RDD by applying a function to each element of this RDD. 
Python :: python loop over s3 objects] 
Python :: timedelta64 total_mins 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =