Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5944421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:32:06+00:00 2026-05-22T16:32:06+00:00

Unfortunately, I’m working with an extremely large corpus which is spread into hundreds of

  • 0

Unfortunately, I’m working with an extremely large corpus which is spread into hundreds of .gz files — 24 gigabytes (packed) worth, in fact. Python is really my native language (hah) but I was wondering if I haven’t run up against a problem that will necessitate learning a “faster” language?

Each .gz file contains a single document in plain text, is about 56MB gzipped, and about 210MB unzipped.

On each line is an n-gram (bigram, trigram, quadrigram, etc.) and, to the right, a frequency count. I need to basically create a file that stores the substring frequencies for each quadrigram alongside its whole-string frequency count (i.e., 4 unigram frequencies, 3 bigram frequencies, and 2 trigram frequencies for a total of 10 data points). Each type of n-gram has its own directory (e.g., all bigrams appear in their own set of 33 .gz files).

I know an easy, brute force solution, and which module to import to work with gzipped files in Python, but I was wondering if there was something that wouldn’t take me weeks of CPU time? Any advice on speeding this process up, however slightly, would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:32:07+00:00Added an answer on May 22, 2026 at 4:32 pm

    It would help to have an example of a few lines and expected output. But from what I understand, here are some ideas.

    You certainly don’t want to process all files every time you process a single file or, worse, a single 4-gram. Ideally you’d go through each file once. So my first suggestion is to maintain an intermediate list of frequencies (these sets of 10 data points), where they first only take into account one file. Then when you process the second file, you’ll update all the frequencies for items that you encounter (and presumably add new items). Then you’ll keep going like this, increasing frequencies as you find more matching n-grams. At the end write everything out.

    More specifically, at each iteration I would read a new input file into memory as a map of string to number, where the string is, say, a space-separated n-gram, and the number is its frequency. I would then process the intermediate file from the last iteration, which would contain your expected output (with incomplete values), e.g. “a b c d : 10 20 30 40 5 4 3 2 1 1” (kind of guessing the output you are looking for here). For each line, I’d look up in the map all the sub-grams in my map, update the count, and write out the updated line to the new output file. That one will be used in the next iteration, until I’ve processed all input files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unfortunately, I'm working with some 3rd party javascript, which inserts links into my pages.
Unfortunately I've got a bug that I have been working on for 1 full
Unfortunately, SQL Server can not a handle a parameter list which exceeds 2100 parameters.
Unfortunately, I cannot use either fopen or file_get_contents, so my working script has become
Unfortunately, the Mac I'm working on does not allow us to attach a debugger,
Unfortunately, on a site that I'm working on, the StreetView image of the business
Unfortunately, my question is not as simple as keeping track of two windows created
Unfortunately it looks like for various reasons I'm going to have to use Visual
Unfortunately, there seems to be no string.Split(string separator), only string.Split(char speparator). I want to
Unfortunately, I need to do this. I'm using ELMAH for my error log. Before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.