<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def infer_country(self, doc):
 """NLP a doc, find its entities, get their features, and return the model's country guess for each. Maybe use a better name. Parameters doc: str or spaCy the document to country-resolve the entities in Returns ------- proced: list of dict the feature output of "make_country_features" updated with the model's estimated country for each entity. E.g.: {'all_confidence': array([ 0.95783567, 0.03769876, 0.00454875], dtype=float32), 'all_countries': array(['SYR', 'USA', 'JAM'], dtype='<U3'), 'country_conf': 0.95783567, 'country_predicted': 'SYR', 'features': {'ct_mention': '', 'ct_mention2': '', 'ctm_count1': 0, 'ctm_count2': 0, 'first_back': 'JAM', 'maj_vote': 'SYR', 'most_alt': 'USA', 'most_pop': 'SYR', 'word_vec': 'SYR', 'wv_confid': '29.3188'}, 'label': 'Syria', 'spans': [{'end': 26, 'start': 20}], 'text': "There's fighting in Aleppo and Homs.", 'word': 'Aleppo'} """

        if not hasattr(doc, "ents"):
            doc = nlp(doc)
        proced = self.make_country_features(doc, require_maj=False)
        if not proced:
            pass
            # logging!
            #print("Nothing came back from make_country_features")
        feat_list = []
        #proced = self.ent_list_to_matrix(proced)

        for loc in proced:
            feat = self.make_country_matrix(loc)
            #labels = loc['labels']
            feat_list.append(feat)
            #try:
            # for each potential country...
            for n, i in enumerate(feat_list):
                labels = i['labels']
                try:
                    prediction = self.country_model.predict(i['matrix']).transpose()[0]
                    ranks = prediction.argsort()[::-1]
                    labels = np.asarray(labels)[ranks]
                    prediction = prediction[ranks]
                except ValueError:
                    prediction = np.array([0])
                    labels = np.array([""])

            loc['country_predicted'] = labels[0]
            loc['country_conf'] = prediction[0]
            loc['all_countries'] = labels
            loc['all_confidence'] = prediction

        return proced