The objective of this project is to explore the SwiftKey text corpus and understand word frequencies, common word combinations and vocabulary patterns.
This analysis will help prepare the data for building a predictive text application.
The analysis uses three English-language datasets:
The original datasets contain the following number of lines:
| Source | Original lines | Approx. file size | Sampled documents |
|---|---|---|---|
| Blogs | 899,288 | 200.4 MB | 10,000 |
| News | 77,259 | 196.3 MB | 10,000 |
| 2,360,148 | 159.4 MB | 10,000 |
A sample of 10,000 documents was selected from each dataset to reduce memory usage. The analysis therefore uses 30,000 sampled documents in total.
## [1] 10000
## [1] 10000
## [1] 10000
## [1] 30000 3
## # A tibble: 3 × 4
## source documents total_words average_words_per_document
## <chr> <int> <int> <dbl>
## 1 blogs 10000 414499 41.4
## 2 news 10000 345925 34.6
## 3 twitter 10000 127043 12.7
The sample contains 30,000 documents and approximately 887,467 words, based on the word-count calculation. Blogs have the highest average document length (41.45 words), followed by news (34.59 words) and Twitter (12.70 words). This reflects differences in content and writing style across the three sources.
## [1] 1047294 3
## token n
## 1 the 43723
## 2 to 24252
## 3 and 22874
## 4 a 21607
## 5 of 18725
## 6 in 15012
## 7 i 13273
## 8 that 9385
## 9 for 9343
## 10 is 9201
## 11 it 7854
## 12 on 6854
## 13 you 6585
## 14 with 6402
## 15 was 5849
## 16 this 4879
## 17 as 4799
## 18 at 4746
## 19 be 4699
## 20 my 4597
# 9. Bigram Analysis
## bigram n
## 1 of the 4122
## 2 in the 3760
## 3 to the 1935
## 4 for the 1712
## 5 on the 1689
## 6 to be 1476
## 7 and the 1243
## 8 at the 1229
## 9 in a 1104
## 10 with the 956
## 11 it was 939
## 12 is a 919
## 13 from the 853
## 14 for a 805
## 15 and i 782
## 16 with a 775
## 17 i was 772
## 18 it is 771
## 19 of a 715
## 20 as a 713
# 11. Trigram Analysis
## trigram n
## 1 one of the 344
## 2 a lot of 294
## 3 to be a 170
## 4 out of the 150
## 5 some of the 145
## 6 as well as 144
## 7 the end of 138
## 8 it was a 136
## 9 going to be 135
## 10 be able to 115
## 11 thanks for the 115
## 12 i want to 113
## 13 part of the 101
## 14 a couple of 99
## 15 this is a 97
## 16 it would be 89
## 17 i have a 88
## 18 the first time 88
## 19 end of the 86
## 20 for the first 84
# 13. Vocabulary Coverage
## unique_words words_for_50 words_for_90
## 1 48146 144 7223
## unrecognised_unique_words total_occurrences percentage_of_occurrences
## 1 19840 53571 6.131896
## original_vocabulary stemmed_vocabulary vocabulary_reduction
## 1 48146 33101 15045
## reduction_percentage
## 1 31.2487
The exploratory analysis produced the following findings:
The next stage will involve developing a predictive text model using n-gram language modelling.
The planned approach includes:
A Shiny application will be developed to provide an interactive interface. Users will enter text, and the application will display suggested next words based on the prediction model.
This exploratory data analysis provided an understanding of word frequencies, common word combinations and vocabulary patterns in the SwiftKey corpus.
The analysis identified frequently occurring words, bigrams and trigrams. Vocabulary coverage showed that a relatively small number of common words account for a large proportion of word occurrences.
Dictionary-based analysis and stemming also provided insights into vocabulary characteristics and possible optimisation techniques.
These findings will support the next stage of the project: developing a predictive text model using n-grams to suggest the next word based on previously entered words.