Hidden package of Markov models in R

I need help implementing the HMM module in R. I am new to R and don't have much knowledge about this. So I have to implement IE using HMM, I have two folders with files, one with sentences, and the other with the corresponding tags that I want to learn from each sentence.

folder1 > event1.txt: "2013 2nd International Conference on Information and Knowledge Management (ICIKM 2013) will be held in Chengdu, China during July 20-21, 2013." folder2 > event1.txt: "N: 2nd International Conference on Information and Knowledge Management (ICIKM 2013) D: July 20-21, 2013 L: Chengdu, China" N -> Name; D -> Date; L -> Location 

My question is how to implement it on R, how to initialize the model, and how to do it to train it? And how can I apply it to a random sentence to extract information?

Thanks in advance for your help!

+4
source share
4 answers

If you run the following command:

 RSiteSearch('hidden markov model') 

Then it finds 4 types of tasks, 40 vignettes and 255 functions (when I started it, maybe more by the time you run it).

I would suggest looking at these results (perhaps starting with views and blaming) to see that something is working with you. If not, tell us what you have tried and what you need, what is not provided there.

+8
source

I'm not sure what exactly you want to do, but you can find this great tutorial on hidden Markov models using R. You build functions and Markov models from scratch, starting with ordinary Markov models, and then move on to hidden Markov models. It is really important to understand how they work.

There is also the R depmixS4 package for specifying and installing hidden Markov models. The documentation is pretty solid, and sample code can help you.

+8
source

depmixS4 is the most common and reasonably good package if you earn it over your data. He checked for dummy data for me, but gave an error on real data. HMM also works, but only if you have discrete variables and are not continuous.

+2
source

DepmixS4 is what you are looking for.

First of all, you need to determine the maximum number of hidden states for your model. This can be done by taking the model with the lowest AIC for different hidden states.

I created the function HMM_model_execution, which will return the model variable and the number of states for the model.

  library(depmixS4) 
  • the first column should be visible and the remaining external variable in doc_data p>

     HMM_model_execution<-function( doc_data, k) 
  • k amount of total latent state for comparison

     { aic_values <- vector(mode="numeric", length=k-1) # to store AIC values for( i in 2:k) { print(paste("loop counter",i)) mod <- depmix(response = doc_data$numpresc ~ 1, data = doc_data, nstates = i) fm <- fit(mod, verbose = FALSE) aic_values[i-1]<- AIC(fm) #print(paste("Aic value at this index",aic_values[i-1])) #writeLines("\n") } min_index<-which.min(aic_values) 
  • no hidden states for a better model

     #print(paste("index of minimum AIC",min_index)) mod <- depmix(response = doc_data$numpresc ~ 1, data = doc_data, nstates = (min_index+1)) fm <- fit(mod, verbose = FALSE) 
  • best model performance

     print(paste("best model with number of hidden states", min_index+1)) return(c(fm, min_index+1)) writeLines("\n") writeLines("\n") 

External variables (co-variates can be passed to depmix functions). summary (fm) will give you all the model parameters.

0
source

Source: https://habr.com/ru/post/1491826/


All Articles