Fix bugs in generalization and read_data.py