Setup data for dynamic topic modelling - python

I'm trying to learn dynamic topic modeling(to capture the semantic changes in the words) from data scrapped from PUBMED. I was able to get the data in the form of xml and was able to extract the "abstract" text and the date information off of it and saved that in the csv format. (But this is just a part of the data.)
Format obtained
Year|month|day|abstractText
I'm planning on using gensim lda for my model
I've never really done topic modeling before and need your help with guiding me through this process one step at a time.
Questions:
Is csv a preferred format to feed into gensim lda?
for dynamic modeling, how should the time aspect of the data be captured and used in the model?
is there a better way to organize the data than in csv files?
Should i use the bodytext instead of the abstract for this?
Hope I learn a lot from this. Thanks in advance.

Related

How to summarize transcripts of dialogue in Python?

I am carrying out a project in which I wish to create summaries of podcast transcripts.
I am aware of tools like NLTK & spaCy that can be used for text summarization, is there a way I could use datasets that focus on dialogue, such as MediaSum, SAMsum or the Spotify Podcast Dataset with these tools as to produce appropriate summaries?
Must I create a model and train it on the mentioned corpora?
How would I do this and then make use of said model in python?
Any help or insight into this task would be greatly appreciated.
I am in the research phase and have identified datasets that I believe could aid me in my summarization of dialogue transcripts, but I do not yet know how to achieve my final goal of using these along with a existing or newly created model as to generate appropriate summarizations of dialogue.

Huggingface NER with custom data

I have a csv data as below.
**token** **label**
0.45" length
1-12 size
2.6" length
8-9-78 size
6mm length
Whenever I get the text as below
6mm 8-9-78 silver head
I should be able to say length = 6mm and size = 8-9-78. I'm new to NLP world, I'm trying to solve this using Huggingface NER. I have gone through various articles. I'm not getting how to train with my own data. Which model/tokeniser should I make use of? Or should I build my own? Any help would be appreciated.
I would maybe look at spaCy's pattern matching + NER to start. The pattern matching rules spacy provides are really powerful, especially when combined with their statistical NER models. You can even use the patterns you develop to create your own custom NER model. This will give you a good idea of where you still have gaps or complexity that might require something else like Huggingface, etc.
If you are willing to pay, you can also leverage prodigy which provides a nice UI with Human In the Loop interactions.
Adding REGEX entities to SpaCy's Matcher
I had two options one is Spacy (as suggested by #scarpacci) and other one is SparkNLP. I opted for SparkNLP and found a solution. I formatted the data in CoNLL format and trained using Spark's NerDlApproach and GLOVE word embedding.

Perform Named Entity Recognition - NLP

I am trying to learn how to perform Named Entity Recognition.
I have a set of discharge summaries containing medical information about patients. I converted my unstructured data into structured data. Now, I have a DataFrame that looks like this:
Text | Target
normal coronary arteries... R060
The Text column contains information about the diagnosis of a patient, and the Target column contains the code that will need to be predicted in a further task.
I have also constructed a dictionary that looks like this:
Code (Key) | Term (Value)
A00 Cholera
This dictionary brings information about each diagnosis and the afferent code. The term column will be used to identify the clinical entities in the corpus.
I will need to train a classifier and predict the code in order to automate the process of assigning codes for the discharge summaries (I am explaining this to have an idea about the task I'm performing).
Until now I have converted my data into a structured one. I am trying to understand how I should perform Named Entity Recognition to label the medical terminology. I would like to try direct matching and fuzzy matching but I am not sure what are the previous steps. Should I perform tokenizing, stemming, lemmatizing before? Or firstly should I find the medical terminology as clinical named entities are often multi-token terms with nested structures that include other named entities inside them? Also what packages or tools are you recommending me to use in Python?
I am new in this field so any help will be appreciated! Thanks!
If you are asking for building a classification model, then you should go for deep learning. Deep learning is highly efficient in classification.
While dealing with such type of language processing tasks, I recommend you to first tokenize your text and do padding. Basic tokenization should be enough, but you can go for more preprocessing like basic string processing because proper preprocessing can improve your model accuracy upto 3% or 4%. For basic string processing, you can use regex(built-in package called re) in python.
https://docs.python.org/3/library/re.html
I think, you are doing mapping after preprocessing. Mapping should be enough for tasks like classification, but I recommend you to learn about word embeddings. Word embedding will improve your model.
For all these tasks, i recommend you to use tensorflow. Tensorflow is famous tool for machine learning, language processing, image processing, and much more. You can learn natural language processing from official tensorflow documentation. They have provided all learning material in tensorflow tutorial section.
https://www.tensorflow.org/tutorials/
I think, this will help you. All the best for your work!!!!
Thank you.

What is the most efficient way to extract tweets that has certain dialect?

I'm doing text classification for Arabic dialects, and I need to collect data. So I'm using Twitter API to do that.
However, the problem is:
I need to find tweets that have the same dialect.
One solution I have is:
Is to collect tweets based on certain keywords only one dialect have
one problem with that solution is:
When I test the data, of course the accuracy will be high. Because the test data will contain those keywords that I used to collect the dataset.
what I'm looking for
Isn't there another way to circumvent this bias?
Note that this is a platform to get advice with particular code, not to discuss methodologies.
That said, you could manually collect data from this particular dialect and collect other tweets as well and then build a classifier that predicts to what group a tweet belongs.

Parsing date from OCR response in Python

I am trying to read date from an OCR response of an image. The OCR output is something like this.
\nPatientsName:KantibhaiPatelAgeISex:71YearslMale\nRef.by:Dr.KetanShuklaMS.MCH.\nReg.Date:29/06/201519;03\nLabRefNo;ARY-8922-15ReportingDate.29/06/201519:10\nHEMOGRAMREPORT\nTESTRESULTREFERENCEINTERVAL\n
I am interested in extracting the reporting date i.e. 29/06/2015. Also I am interested in storing the patient details in a database (MongoDB) chronologically. Hence I need to store the date in a standardized format for easy future queries.
All suggestions are welcomed.
Edit - Since the data is coming as an OCR response there tends to be a lot of noise and sometimes misinterpreted characters. Is there any method that can have a better fault tolerance for string searching.
re.search(r'Date:([0-9]{2}\/[0-9]{2}\/[0-9]{4})', ocr_response).group(1)
The above statement explicitly looks for numbers, but what if some number is not read or misinterpeted as a character ?
use re module:
import re
print re.search(r'[Date:]*([0-9]{0,2}[\/-]([0-9]{0,2}|[a-z]{3})[\/-][0-9]{0,4})', ocr_response).group(1)
Output:
29/06/2015
You should go with good NER(Named,Entity Recognition) model, you can custom train your own model if you have good amount of annotated training data or you can use pre-trained models which does not require annotated dataset.
Spacy is a good Python library for NER. Have a look on the link below-
https://spacy.io/
It uses deep neural networks at the backend to recognize various entities present in the text (date in your case).
Hope it gives you an alternative to regular expression, thanks for the upvote in advance.

Categories