Skip to content

Speed improvement for bind_tf_idf #237

Description

@sometimesabird

Hey, guys, I noticed that bind_tf_idf() doesn't really use dplyr, which has better performance relative to base R. I had a 30% improvement in speed for getting tfidf for a corpus of 100,000 tweets using this code:

corpus %>%
  group_by(TextID, word) %>% 
  count() %>% 
  group_by(TextID) %>% 
  mutate(tf = n / sum(n)) %>% 
  group_by(word) %>% 
  mutate(Documents = n()) %>% 
  ungroup() %>% 
  mutate(idf = log(length(unique(TextID)) / Documents),
         tf_idf = tf * idf)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions