Package: iQual
iQualThis repository contains the code and resources necessary to implement the techniques described in the paperA Method to Scale-Up Interpretative Qualitative Analysis, with an Application to Aspirations in Cox’s Bazaar, Bangladesh. TheiQualpackage is designed for qualitative analysis of open-ended interviews and aims to extend a small set of interpretative human-codes to a much larger set of documents using natural language processing. The package provides a method for assessing the robustness and reliability of this approach. TheiQualpackage has been applied to analyze 2,200 open-ended interviews on parent’s aspirations for children from Rohingya refugees and their Bangladeshi hosts in Cox’s Bazaar, Bangladesh. It draws on work in anthropology and philosophy to expand conceptions of aspirations in economics to distinguish between material goals, moral and religious values, and navigational capacity—the ability to achieve goals and aspirations, showing that they have very different correlates.WithiQual, researchers can efficiently analyze large amounts of qualitative data while maintaining the nuance and accuracy of human interpretation.InstallationTo installiQualusing pip, use the following command:pipinstall-UiQualAlternatively, you can installiQualfrom source. To do so, use the following commands:gitclonehttps://github.com/worldbank/iQual.gitcdiQual
pipinstall-e.DependenciesiQualrequires Python 3.7+ and the following dependencies:pandasscikit-learnsentence-transformersspaCynumpyumap-learnscipystatsmodelssimplejsonmatplotlibseabornFeaturesiQualis a package designed for qualitative analysis of open-ended interviews. It allows researchers to efficiently analyze large amounts of qualitative data while maintaining the nuance and accuracy of human interpretation.Customizable pipelines usingscikit-learnpipelinesText-vectorization using:Any of thescikit-learntext feature extraction method.Anysentence-transformerscompatible model.AnyspaCymodel with adoc.vectorattribute.Classification using anyscikit-learnclassification methodFeature Transformation:Dimensionality reduction using anyscikit-learndecompositionmethod, or UMAP usingumap-learn.Feature scaling using anyscikit-learnpreprocessingmethod.Model selection and performance evaluation usingscikit-learnmethods.Model performance evaluation usingscikit-learnmetrics.Tests for bias and interpretability, withstatsmodels.Basic UsageThe following code demonstrates the basic usage of theiQualpackage. It shows how to construct a pipeline, fit it to the data, and use it to classify new data.Import theiqualpackage and initiate the model class.fromiqualimportiqualnlp# Import `iqualnlp` from the `iqual` packageiqual_model=iqualnlp.Model()# Initiate the model classAdd text features to the model. Theadd_text_featuresmethod takes the following arguments:question_col: The name of the column containing the question text.answer_col: The name of the column containing the answer text.model: Name of a scikit-learn, spaCy, sentence-transformers, or a precomputed vector (picklized dictionary) model. The default isTfidfVectorizer.env: The environment or package which is being used. The default isscikit-learn. Available options arescikit-learn,spacy,sentence-transformers, andsaved-dict.**kwargs: Additional keyword arguments to pass to the model.# Use a scikit-learn feature extraction methodiqual_model.add_text_features(question_col,answer_col,model='TfidfVectorizer',env='scikit-learn')# OR - Use a sentence-transformers modeliqual_model.add_text_features(question_col,answer_col,model='all-mpnet-base-v2',env='sentence-transformers')# OR - Use a spaCy modeliqual_model.add_text_features(question_col,answer_col,model='en_core_web_lg',env='spacy')# OR - Use a precomputed vector (picklized dictionary)iqual_model.add_text_features(question_col,answer_col,model='qa_precomputed.pkl',env='saved-dict')(OPTIONAL)Add a feature transformation layer. Theadd_feature_transformermethod takes the following arguments:name: The name of the feature transformation layer.transformation: The type of transformation. Available options areFeatureScalerandDimensionalityReduction.To add afeature scalinglayer, use the following code:iqual_model.add_feature_transformer(name='Normalizer',transformation="FeatureScaler")# or any other scikit-learn scalerTo add adimensionality reductionlayer, use the following code:iqual_model.add_feature_transformer(name='UMAP',transformation="DimensionalityReduction")# supports UMAP or any other scikit-learn decomposition methodAdd a classifier layer. Theadd_classifiermethod takes the following arguments:name: The name of the classifier layer. The default isLogisticRegression.**kwargs: Additional keyword arguments to pass to the classifier.iqual_model.add_classifier(name="LogisticRegression")#  Add a classifier layer from scikit-learn(OPTIONAL)Add a threshold layer for the classifier usingadd_thresholdiqual_model.add_threshold()# Add a threshold layer for the classifier, recommended for imbalanced dataCompile the model withcompile.iqual_model.compile()# Compile the modelFit the model to the data usingfit. Thefitmethod takes the following arguments:X_train: The training data. (pandas dataframe)y_train: The training labels. (pandas series)iqual_model.fit(X_train,y_train)# Fit the model to the dataPredict the labels for new data usingpredict. Thepredictmethod takes the following arguments:X_test: The test data. (pandas dataframe)y_pred=iqual_model.predict(X_test)# Predict the labels for new dataFor examples on cross-validation fitting, model selection & performance evaluation, bias, interpretability and measurement tests, refer to thenotebooksfolder.NotebooksThenotebooksfolder contains detailed examples on usingiQual. The notebooks are organized into the following categories:Basic ModellingThese notebooks demonstrates the basic usage of the package, the pipeline construction, and the vectorization and classification options.Advanced ModellingThese notebooks demonstrate advanced pipeline construction, mixing and matching of feature extraction and classification methods, and model selection.InterpretabilityThese notebooks demonstrate the interpretability and related tests for measurement and comparison of interpretability across human and enhanced (machine + human) codes.BiasandEfficiencyThese notebooks demonstrate the bias and efficiency tests for determining the value and validity of enhanced codes.Citation & AuthorsIf you use this package, please cite the following paper:A Method to Scale-Up Interpretative Qualitative Analysis, with an Application to Aspirations in Cox’s Bazaar, BangladeshAshwin,Julian; Rao,Vijayendra; Biradavolu,Monica Rao; Chhabra,Aditya; Haque,Arshia; Khan,Afsana Iffat; Krishnan,Nandini.
A Method to Scale-Up Interpretative Qualitative Analysis, with an Application to Aspirations in Cox’s Bazaar, Bangladesh (English). (Policy Research Working Paper No. WPS 10046)
Paper is funded by the Knowledge for Change Program (KCP) Washington, D.C. : World Bank Group.
http://documents.worldbank.org/curated/en/099759305162210822/IDU0a357362e00b6004c580966006b1c2f2e3996MaintainersPlease contact the following people for any queries regarding the package:Aditya Karan ChhabraJulian Ashwin