Solving a Python dictionary structure memory spike problem

Source: Internet
Author: User

Background: When reading a key value data, the Python dictionary structure causes memory usage to expand by about 10 times times and is not tolerated. This article solves this problem

Data: Word2vec The result of the training, word corresponds to a 400-D word vector. A total of 1.6G around the glossary

Solution: Use Python's class array for resolution.

Step: 1, convert raw data into Key,index and binary Value data block file, where binary Value data block size is 750M

2, the array after loading in accordance with the index query effect: Only about 800M of memory, greatly reducing the use of memory. Query using: vec[i] + = Word2vec_array[index*word2vec_dim + i]

Pei Zhi

Solving a Python dictionary structure memory spike problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.